Help Center/ OBS Nodejs SDK/ API Reference/ Initialization/ Result Returned via the Promise Object
Updated on 2023-03-16 GMT+08:00

Result Returned via the Promise Object

Description

ObsClient supports results returned via the Promise object. If no exception is caught by the catch method of the Promise object, the API calling is complete. In such conditions, you need to obtain the HTTP status code from the SDK common result object to check whether the operation is successful.

Sample Code

obsClient.putObject({
       Bucket : 'bucketname',
       Key : 'objectkey',
       Body : 'Hello OBS'
}).then((result) => {
    if(result.CommonMsg.Status < 300){
        if(result.InterfaceResult){
            console.log('Operation Succeed');
        }
    }else{
        console.log('Code-->' + result.CommonMsg.Code); 
        console.log('Message-->' + result.CommonMsg.Message);
        console.log('HostId-->' + result.CommonMsg.HostId);
        console.log('RequestId-->' + result.CommonMsg.RequestId);
    }
}).catch((err) => {
    console.error('Error-->' + err);
});