Updated on 2024-12-03 GMT+08:00

SDK Common Result Objects

After you call an API in an instance of the ObsClient class, a common result object will be returned if the exception information parameter is null. The following table lists the object content:

Field

Type

Description

CommonMsg

Object

Common information generated after the API calling is complete, including HTTP status code and error code.

-

Status

Number

HTTP status code. If the value is smaller than 300, the operation succeeds. Otherwise, the operation fails.

Code

String

Error code on the OBS server. If Status is smaller than 300, the value is null.

Message

String

Error description on the OBS server. If Status is smaller than 300, the value is null.

HostId

String

Requested server ID. If Status is smaller than 300, the value is null.

RequestId

String

Request ID returned by the OBS server

Id2

String

Request ID2 returned by the OBS server

Indicator

String

Detailed error code returned by the OBS server. If Status is smaller than 300, the value is null.

InterfaceResult

Object

Result data generated after the operation is successful. If Status is greater than 300, the value is null.

-

RequestId

String

Request ID returned by the OBS server

Id2

String

Request ID2 returned by the OBS server

Other fields

For details, see the OBS BrowserJS SDK API Reference.

Sample code for processing public result objects:

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables AccessKeyID and SecretAccessKey.
    // The front-end code does not have the process environment variable, so you need to use a module bundler like webpack to define the process variable.
    // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    access_key_id: process.env.AccessKeyID,
    secret_access_key: process.env.SecretAccessKey,
    // Replace the example endpoint with the actual one in your case.
    server: 'https://obs.ap-southeast-1.myhuaweicloud.com'
});

// Call APIs to perform related operations, for example, downloading an object.
obsClient.getObject({
       Bucket : 'bucketname',
       Key : 'objectname',
}, function (err, result) {
       if(!err){
              if(result.CommonMsg.Status < 300){
                     // Obtain the request ID.
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     // Obtain other parameters.
                     console.log('Content-->' + result.InterfaceResult.Content);
              }else{
                     // Obtain Code and Message.
                     console.log('Code-->' + result.CommonMsg.Code); 
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});