Object Storage Service (OSS) SDK for Java exceptions are classified into two types: OSSException and ClientException. Both types are subclasses of RuntimeException.
Examples
The following sample code provides an example on how to handle exceptions:
try {
// Perform operations on OSS such as object upload.
ossClient.putObject(...);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message: " + oe.getErrorMessage());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message: " + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
ClientException
ClientException indicates an exception that occurs when a client sends a request or transmits data to OSS. For example, ClientException is returned when the client fails to send a request due to network disconnection. ClientException is also returned when an I/O exception occurs during object upload.
OSSException
OSSException indicates a server exception that arises from the resolution of a server error message. OSSException includes the error code and error message returned by OSS. This way, you can identify and resolve the error.
OSSException includes the following error information:
Parameter | Description |
Code | The error code that is returned by OSS. |
Message | The detailed error message returned by OSS. |
RequestId | The UUID used to uniquely identify the request. If the problem persists, you can provide the request ID to the OSS development engineers to obtain technical support. |
HostId | The ID of the host in the accessed OSS cluster, which is the same as the host ID specified in the request. |
Common OSS error codes
Error code | Description | HTTP status code |
AccessDenied | The access is denied. | 403 |
BucketAlreadyExists | The bucket already exists. | 409 |
BucketNotEmpty | The bucket is not empty. | 409 |
EntityTooLarge | The entity size exceeds the maximum limit. | 400 |
EntityTooSmall | The entity size is below the minimum limit. | 400 |
FileGroupTooLarge | The object group size exceeds the maximum limit. | 400 |
FilePartNotExist | The object part does not exist. | 400 |
FilePartStale | The object part has expired. | 400 |
InvalidArgument | The format of the parameter is invalid. | 400 |
InvalidAccessKeyId | The AccessKey ID does not exist. | 403 |
InvalidBucketName | The bucket name is invalid. | 400 |
InvalidDigest | The digest is invalid. | 400 |
InvalidObjectName | The object name is invalid. | 400 |
InvalidPart | The object part is invalid. | 400 |
InvalidPartOrder | The part sequence is invalid. | 400 |
InvalidTargetBucketForLogging | The bucket for logging is invalid. | 400 |
InternalError | An internal OSS error occurred. | 500 |
MalformedXML | The XML format is invalid. | 400 |
MethodNotAllowed | The method is not supported. | 405 |
MissingArgument | Some required parameters are not specified. | 411 |
MissingContentLength | The content length is missing. | 411 |
NoSuchBucket | The bucket does not exist. | 404 |
NoSuchKey | The object does not exist. | 404 |
NoSuchUpload | The multipart upload ID does not exist. | 404 |
NotImplemented | The method cannot be implemented. | 501 |
PreconditionFailed | An error occurred during preprocessing. | 412 |
RequestTimeTooSkewed | The time deviation of the OSS client and OSS server exceeds 15 minutes. | 403 |
RequestTimeout | The request timed out. | 400 |
SignatureDoesNotMatch | A signature error occurred. | 403 |
InvalidEncryptionAlgorithmError | The encryption algorithm is invalid. | 400 |