| 167 | // (e.g. "When completing multipart upload to bucket 'xxx', key 'xxx': ...") |
| 168 | template <typename ErrorType> |
| 169 | Status ErrorToStatus(const std::string& prefix, const std::string& operation, |
| 170 | const Aws::Client::AWSError<ErrorType>& error, |
| 171 | const std::optional<std::string>& region = std::nullopt) { |
| 172 | // XXX Handle fine-grained error types |
| 173 | // See |
| 174 | // https://sdk.amazonaws.com/cpp/api/LATEST/namespace_aws_1_1_s3.html#ae3f82f8132b619b6e91c88a9f1bde371 |
| 175 | auto error_type = static_cast<Aws::S3::S3Errors>(error.GetErrorType()); |
| 176 | std::stringstream ss; |
| 177 | ss << S3ErrorToString(error_type); |
| 178 | if (error_type == Aws::S3::S3Errors::UNKNOWN) { |
| 179 | ss << " (HTTP status " << static_cast<int>(error.GetResponseCode()) << ")"; |
| 180 | } |
| 181 | |
| 182 | // Possibly an error due to wrong region configuration from client and bucket. |
| 183 | std::optional<std::string> wrong_region_msg = std::nullopt; |
| 184 | if (region.has_value()) { |
| 185 | const auto maybe_region = BucketRegionFromError(error); |
| 186 | if (maybe_region.has_value() && maybe_region.value() != region.value()) { |
| 187 | wrong_region_msg = " Looks like the configured region is '" + region.value() + |
| 188 | "' while the bucket is located in '" + maybe_region.value() + |
| 189 | "'."; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | auto request_id = error.GetRequestId(); |
| 194 | auto request_str = request_id.empty() ? "" : (" (Request ID: " + request_id + ")"); |
| 195 | |
| 196 | return Status::IOError(prefix, "AWS Error ", ss.str(), " during ", operation, |
| 197 | " operation: ", error.GetMessage(), request_str, |
| 198 | wrong_region_msg.value_or("")); |
| 199 | } |
| 200 | |
| 201 | template <typename ErrorType, typename... Args> |
| 202 | Status ErrorToStatus(const std::tuple<Args&...>& prefix, const std::string& operation, |
no test coverage detected