The OSS PHP SDK throws an `OssException` for errors such as invalid parameters and non-existent files. You can use the `getMessage` method to retrieve the error message.
For more information about `OssException`, see GitHub.
Exception handling example
The following code shows how to handle an exception that is thrown when you try to create a bucket that already exists. The code prints the error message.
try {
$ossClient->createBucket($bucket);
} catch (OssException $e) {
print("Exception:" . $e->getMessage() . "\n");
}
You can also obtain the following information:
Parameter | Description |
HTTPStatus | The HTTP status code. Use the `getHTTPStatus` method to get this value. |
ErrorCode | The error code that OSS returns. Use the `getErrorCode` method to get this value. |
ErrorMessage | The error message that OSS returns. Use the `getErrorMessage` method to get this value. |
RequestId | A universally unique identifier (UUID) that uniquely identifies the request. If you cannot resolve an issue, provide this RequestId to an OSS developer for assistance. Use the `getRequestId` method to get this value. |
Details | A detailed description of the error message that OSS returns. Use the `getDetails` method to get this value. |
Common OSS error codes
Error code | Description | HTTP status code |
AccessDenied | Access 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 file group is too large. | 400 |
FilePartNotExist | The file part does not exist. | 400 |
FilePartStale | The file part is stale. | 400 |
InvalidArgument | The parameter format 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 part is invalid. | 400 |
InvalidPartOrder | The part order is invalid. | 400 |
InvalidTargetBucketForLogging | The target bucket for the logging operation is invalid. | 400 |
InternalError | An internal error occurred 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 | A pre-processing error occurred. | 412 |
RequestTimeTooSkewed | The difference between the client time and the OSS server time is more than 15 minutes. | 403 |
RequestTimeout | The request timed out. | 400 |
SignatureDoesNotMatch | The signature is incorrect. | 403 |
InvalidEncryptionAlgorithmError | The specified encryption algorithm is incorrect. | 400 |