All Products
Search
Document Center

Object Storage Service:Exception handling (PHP SDK V1)

Last Updated:Oct 12, 2025

The OSS PHP SDK throws an OssException for errors such as invalid parameters or non-existent objects. You can call the getMessage method to obtain the error message.

For more information about OssException, see GitHub.

Exception handling example

The following code provides an example of how to handle an exception that is thrown when you attempt 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. Obtain this value by calling the getHTTPStatus method.

ErrorCode

The error code returned by OSS. Obtain this value by calling the getErrorCode method.

ErrorMessage

The error message returned by OSS. Obtain this value by calling the getErrorMessage method.

RequestId

The universally unique identifier (UUID) of the request. If you cannot resolve an issue, provide the RequestId to OSS developers for assistance. Obtain this value by calling the getRequestId method.

Details

The detailed error message returned by OSS. Obtain this value by calling the getDetails method.

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

Entity 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

Invalid parameter format

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 logging is invalid.

400

InternalError

An internal OSS error occurred.

500

MalformedXML

The XML format is invalid.

400

MethodNotAllowed

The method is not allowed.

405

MissingArgument

A required 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

Unsupported methods

501

PreconditionFailed

A precondition failed.

412

RequestTimeTooSkewed

The time difference between the client and the OSS server is more than 15 minutes.

403

RequestTimeout

The request timed out.

400

SignatureDoesNotMatch

The signature does not match.

403

InvalidEncryptionAlgorithmError

The specified encryption algorithm is invalid.

400