Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
132 stars 148 forks source link

No error code present in extended_error for 416: InvalidRange #395

Open ajs97 opened 3 years ago

ajs97 commented 3 years ago

I have added the error handling code, and this particular error does not have the error code present in the storage_exception. I added this logging:

  HandleException(const azure::storage::storage_exception& e) {
  auto result = e.result();
  int http_status_code = result.http_status_code();
  auto extended_error = result.extended_error();
  cout   << "HTTP Status Code: " << http_status_code
              << " , error_code: " << extended_error.code()
              << " , error message: " << e.what();

I don't get the error code for the InvalidRange error:

HTTP Status Code: 416 , error_code:  , error message: The range specified is invalid for the current size of the resource.

Is this expected? Is there any other error which will return status code 416, or is InvalidRange the only one that has 416?

ljluestc commented 1 year ago

include <azure/storage/common/storage_common.hpp>

include <azure/storage/blobs/blob_service_client.hpp>

void HandleException(const azure::storage::storage_exception& e) { auto result = e.result(); int http_status_code = result.http_status_code(); auto extended_error = result.extended_error();

if (http_status_code == 416) {
    // Handle the InvalidRange error here
    std::cout << "Received InvalidRange error: " << e.what() << std::endl;
} else {
    // Handle other errors
    std::cout << "HTTP Status Code: " << http_status_code
              << " , error_code: " << extended_error.code()
              << " , error message: " << e.what() << std::endl;
}

}