impl(rest): map http code 504 to kUnavailable#16077
impl(rest): map http code 504 to kUnavailable#16077scotthart merged 1 commit intogoogleapis:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the kGatewayTimeout (504) HTTP status code and maps it to StatusCode::kUnavailable. It also updates the AsStatus function to include the HTTP status code in the ErrorInfo metadata when the response payload is empty, with corresponding test updates. Feedback suggests consolidating the status mapping logic to include kBadGateway for consistency with existing tests and optimizing the AsStatus implementation by avoiding redundant string conversions of the status code.
| if (code == HttpStatusCode::kServiceUnavailable) { | ||
| return StatusCode::kUnavailable; | ||
| } | ||
| if (code == HttpStatusCode::kGatewayTimeout) { | ||
| return StatusCode::kUnavailable; | ||
| } |
There was a problem hiding this comment.
These checks can be combined for better readability. Additionally, it appears kBadGateway (502) is also expected to be mapped to kUnavailable based on the test cases (see line 83 of google/cloud/internal/rest_response_test.cc), but it is currently missing from this function. Consider adding it here.
if (code == HttpStatusCode::kServiceUnavailable ||
code == HttpStatusCode::kGatewayTimeout ||
code == HttpStatusCode::kBadGateway) {
return StatusCode::kUnavailable;
}| ErrorInfo error_info{ | ||
| {}, {}, {{"http_status_code", std::to_string(http_status_code)}}}; | ||
| return Status( | ||
| status_code, | ||
| "Received HTTP status code: " + std::to_string(http_status_code), | ||
| std::move(error_info)); |
There was a problem hiding this comment.
The HTTP status code is converted to a string twice. Consider converting it once to improve efficiency. Additionally, ensure to use std::move when passing the local ErrorInfo object to the Status constructor to avoid unnecessary copies, as per repository best practices.
auto code_str = std::to_string(http_status_code);
ErrorInfo error_info{{}, {}, {{"http_status_code", code_str}}};
return Status(status_code, "Received HTTP status code: " + code_str,
std::move(error_info));References
- When passing a local object to a method that takes it by value, use std::move to avoid unnecessary copies.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16077 +/- ##
=======================================
Coverage 92.67% 92.67%
=======================================
Files 2343 2343
Lines 217117 217123 +6
=======================================
+ Hits 201214 201221 +7
+ Misses 15903 15902 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Upcoming RAB feature considers 504 retryable. Additionally, improve returned error status when no payload is available.