Exception handling
Updated at:2025-11-03
When calling the SDK method, exception information will be thrown through the BosResponse instance. Users need to read the BosResponse.error information to check the reason, or access BosResponse.statusCode to view the HTTP status code. The usual usage is as follows:
Plain Text
1try {
2 ....
3} catch(bosResponse) {
4 logger.error(`errCode: ${bosResponse.error.code}`)
5 logger.error(`requestId: ${bosResponse.error.requestId}`)
6 logger.error(`errMessage: ${bosResponse.error.message}`)
7 logger.error(`statusCode: ${bosResponse.statusCode}`)
8}
Note: Any error code outside the range of 200 to 300 will throw an exception. When checking whether an object exists, if it does not exist, a 404 will be returned and an exception will be triggered. In this case, you need to determine whether the HTTP status code is 404 to confirm whether the file does not exist or the request to BOS is unsuccessful.
