Exception handling
Client exception
A client exception occurs when the client encounters issues while sending requests or transmitting data to BOS. For example, when the network connection is unavailable during request sending, the client operation will return non-zero; when an IO exception occurs during file upload, it will also return non-zero.
It will return non-zero when the client executes operations such as put_object and delete_bucket. For specific returned error codes, refer to bcesdk/common/common.h. You can also call the stringfy_ret_code function in the bcesdk/util/util.h to convert the returned error code into a string for printing.
1int ret = client.upload_file("bucketName", "objectName", "fileName");
2if (ret != 0) {
3 std::cout << "client error occurs: " << stringfy_ret_code(ret) << std::endl;
4 return ret;
5}
6 return RET_OK;//RET_OK=0 indicates successful execution
7 // It is recommended to use the request&response standard request API for more standardized requests
Server exception
A server exception is generated when BOS server-side errors occur. The service returns detailed error messages to assist troubleshooting. For common server exceptions, refer to [BOS Error Message Format](BOS/API Reference/Error code.md)
When an exception occurs on the server, the error message will be written into the response for exception handling
1int ret = client.put_object(request, &response);
2if (response.is_fail()) {
3 //Status codes: 0 indicates success, 400~599 indicates HTTP error codes, and 1,000~ indicates client errors
4 // It is recommended to print the requestid to facilitate quickly locating abnormal requests
5 int status = response.status_code();
6 std::string msg = response.error().message();
7 std::string request_id = response.error().request_id();
8 printf("put object fail, [status_code = %d], [message = %s], [requestid = %s]", status, msg.c_str(), request_id.c_str());
9 return status;
10}
11return RET_OK;
