The OSS PHP SDK throws an OssException for errors such as invalid parameters and non-existent files. Use the getMessage method to get the error message.
For the full OssException class definition, see OssException.php on GitHub.
Handle an exception
The following example catches an OssException and prints all available diagnostic information — HTTP status code, error code, error message, RequestId, and details.
try {
$ossClient->createBucket($bucket);
} catch (OssException $e) {
print("Exception: " . $e->getMessage() . "\n");
print("HTTP status: " . $e->getHTTPStatus() . "\n");
print("Error code: " . $e->getErrorCode() . "\n");
print("Error message: " . $e->getErrorMessage() . "\n");
print("Request ID: " . $e->getRequestId() . "\n");
print("Details: " . $e->getDetails() . "\n");
}OssException exposes the following properties:
| Property | Method | Description |
|---|---|---|
| HTTPStatus | getHTTPStatus() | The HTTP status code. |
| ErrorCode | getErrorCode() | The error code that OSS returns. |
| ErrorMessage | getErrorMessage() | The error message that OSS returns. |
| RequestId | getRequestId() | A universally unique identifier (UUID) that identifies the request. If you cannot resolve an issue, provide this RequestId to an OSS developer for assistance. |
| Details | getDetails() | A detailed description of the error message that OSS returns. |
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 exceeds 15 minutes. | 403 |
| RequestTimeout | The request timed out. | 400 |
| SignatureDoesNotMatch | The signature is incorrect. | 403 |
| InvalidEncryptionAlgorithmError | The specified encryption algorithm is incorrect. | 400 |