[bug] Sia provider error responses are not being logged #30
This commit is contained in:
		| @@ -595,6 +595,15 @@ auto sia_provider::remove_directory_impl(const std::string &api_path) | ||||
|   del.path = "/api/bus/objects" + api_path + "/"; | ||||
|   del.query["bucket"] = get_bucket(get_sia_config()); | ||||
|  | ||||
|   std::string error_data; | ||||
|   del.response_handler = [&error_data](auto &&data, long response_code) { | ||||
|     if (response_code == http_error_codes::ok) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     error_data = std::string(data.begin(), data.end()); | ||||
|   }; | ||||
|  | ||||
|   long response_code{}; | ||||
|   stop_type stop_requested{}; | ||||
|   if (not get_comm().make_request(del, response_code, stop_requested)) { | ||||
| @@ -606,7 +615,7 @@ auto sia_provider::remove_directory_impl(const std::string &api_path) | ||||
|  | ||||
|   if (response_code != http_error_codes::ok) { | ||||
|     utils::error::raise_api_path_error(function_name, api_path, response_code, | ||||
|                                        "failed to remove directory"); | ||||
|                                        fmt::format("failed to remove directory|response|", error_data); | ||||
|     return api_error::comm_error; | ||||
|   } | ||||
|  | ||||
| @@ -621,6 +630,15 @@ auto sia_provider::remove_file_impl(const std::string &api_path) -> api_error { | ||||
|   del.path = "/api/bus/objects" + api_path; | ||||
|   del.query["bucket"] = get_bucket(get_sia_config()); | ||||
|  | ||||
|   std::string error_data; | ||||
|   del.response_handler = [&error_data](auto &&data, long response_code) { | ||||
|     if (response_code == http_error_codes::ok) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     error_data = std::string(data.begin(), data.end()); | ||||
|   }; | ||||
|  | ||||
|   long response_code{}; | ||||
|   stop_type stop_requested{}; | ||||
|   if (not get_comm().make_request(del, response_code, stop_requested)) { | ||||
| @@ -632,8 +650,9 @@ auto sia_provider::remove_file_impl(const std::string &api_path) -> api_error { | ||||
|  | ||||
|   if (response_code != http_error_codes::ok && | ||||
|       response_code != http_error_codes::not_found) { | ||||
|     utils::error::raise_api_path_error(function_name, api_path, response_code, | ||||
|                                        "failed to remove file"); | ||||
|     utils::error::raise_api_path_error( | ||||
|         function_name, api_path, response_code, | ||||
|         fmt::format("failed to remove file|response|{}", error_data)); | ||||
|     return api_error::comm_error; | ||||
|   } | ||||
|  | ||||
| @@ -653,11 +672,20 @@ auto sia_provider::rename_file(const std::string &from_api_path, | ||||
|   post.path = "/api/bus/objects/rename"; | ||||
|   post.query["bucket"] = get_bucket(get_sia_config()); | ||||
|  | ||||
|   std::string error_data; | ||||
|   post.response_handler = [&error_data](auto &&data, long response_code) { | ||||
|     if (response_code == http_error_codes::ok) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     error_data = std::string(data.begin(), data.end()); | ||||
|   }; | ||||
|  | ||||
|   long response_code{}; | ||||
|   stop_type stop_requested{}; | ||||
|   if (not get_comm().make_request(post, response_code, stop_requested)) { | ||||
|     utils::error::raise_api_path_error( | ||||
|         function_name, from_api_path + '|' + to_api_path, api_error::comm_error, | ||||
|         function_name, fmt::format("{}|{}", from_api_path, to_api_path), api_error::comm_error, | ||||
|         "failed to rename file"); | ||||
|     return api_error::comm_error; | ||||
|   } | ||||
| @@ -665,8 +693,9 @@ auto sia_provider::rename_file(const std::string &from_api_path, | ||||
|   if (response_code < http_error_codes::ok || | ||||
|       response_code >= http_error_codes::multiple_choices) { | ||||
|     utils::error::raise_api_path_error( | ||||
|         function_name, from_api_path + '|' + to_api_path, response_code, | ||||
|         "failed to rename file file"); | ||||
|         function_name, fmt::format("{}|{}", from_api_path, to_api_path), | ||||
|         response_code, | ||||
|         fmt::format("failed to rename file file|response|{}", error_data)); | ||||
|     return api_error::comm_error; | ||||
|   } | ||||
|  | ||||
| @@ -696,6 +725,15 @@ auto sia_provider::upload_file_impl(const std::string &api_path, | ||||
|   put_file.query["bucket"] = get_bucket(get_sia_config()); | ||||
|   put_file.source_path = source_path; | ||||
|  | ||||
|   std::string error_data; | ||||
|   put_file.response_handler = [&error_data](auto &&data, long response_code) { | ||||
|     if (response_code == http_error_codes::ok) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     error_data = std::string(data.begin(), data.end()); | ||||
|   }; | ||||
|  | ||||
|   long response_code{}; | ||||
|   if (not get_comm().make_request(put_file, response_code, stop_requested)) { | ||||
|     utils::error::raise_api_path_error(function_name, api_path, source_path, | ||||
| @@ -705,8 +743,9 @@ auto sia_provider::upload_file_impl(const std::string &api_path, | ||||
|   } | ||||
|  | ||||
|   if (response_code != http_error_codes::ok) { | ||||
|     utils::error::raise_api_path_error(function_name, api_path, source_path, | ||||
|                                        response_code, "failed to upload file"); | ||||
|     utils::error::raise_api_path_error( | ||||
|         function_name, api_path, response_code, | ||||
|         fmt::format("failed to upload file|response|{}", error_data)); | ||||
|     return api_error::comm_error; | ||||
|   } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user