Exception handling

Last Updated: Nov 02, 2017

The operation is failed if an exception is thrown when you call an OSSClient-class interface. Similarly, the operation is successful when no exception is thrown. When an exception is thrown, the data returned by the method is invalid. When the OSSClient-class interface suffers an exception, it throws the exception class OssException.

Exception handling example

  1. try {
  2. $ossClient->createBucket($bucket);
  3. } catch (OssException $e) {
  4. print("Exception:" . $e->getMessage() . "\n");
  5. }

OSSException

OSSException includes two types:

  • Client exception, including invalid parameters and file does not exist error. For this type of error, you can get the error information using the OssException::getMessage() method.

  • Server exception, refers to the error returned by the OSS, such as no permission, or the file does not exist error. For this type of error, you can get the error information using the OssException::getMessage() method. This type of exception also includes the following information:

    • HTTPStatus: HTTP status code. You can get the status code using the getHTTPStatus() method.

    • ErrorCode: The error code returned by OSS. You can get the error code using the getErrorCode() method.

    • ErrorMessage: The error description provided by OSS. You can get the error message using the getErrorMessage() method.

    • RequestId: The UUID that uniquely identifies the request. When you cannot solve the problem, you can seek help from OSS development engineers by providing this RequestId. You can get the request ID using the getRequestId() method.

    • Details: The original text of the error information returned by the OSS. You can get the error details using the getDetails() method.

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 is too large 400
EntityTooSmall The entity is too small 400
FileGroupTooLarge The object group is too large 400
FilePartNotExist The object part does not exist 400
FilePartStale The object part has expired 400
InvalidArgument The parameter format is invalid 400
InvalidAccessKeyId The AccessKeyID 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 part is invalid 400
InvalidPartOrder The part order is invalid 400
InvalidTargetBucketForLogging An invalid target bucket exists in the logging operation 400
InternalError An error occurs in OSS 500
MalformedXML The XML format is invalid 400
MethodNotAllowed The method is not supported 405
MissingArgument A parameter is missing 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 processed 501
PreconditionFailed Preconditioning fails 412
RequestTimeTooSkewed The request initiation time exceeds the server time by 15 minutes 403
RequestTimeout The request times out 400
SignatureDoesNotMatch The signature is incorrect 403
InvalidEncryptionAlgorithmError The specified entropy encryption algorithm is incorrect 400
Thank you! We've received your feedback.