-
Notifications
You must be signed in to change notification settings - Fork 440
impl(rest): map http code 504 to kUnavailable #16077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
scotthart
merged 1 commit into
googleapis:main
from
scotthart:rest_http_status_code_504
Apr 13, 2026
+14
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,9 @@ StatusCode MapHttpCodeToStatus5xx(std::int32_t code) { | |
| if (code == HttpStatusCode::kServiceUnavailable) { | ||
| return StatusCode::kUnavailable; | ||
| } | ||
| if (code == HttpStatusCode::kGatewayTimeout) { | ||
| return StatusCode::kUnavailable; | ||
| } | ||
| // 5XX - server errors are mapped to kInternal. | ||
| return StatusCode::kInternal; | ||
| } | ||
|
|
@@ -153,8 +156,12 @@ Status AsStatus(HttpStatusCode http_status_code, std::string payload) { | |
| if (payload.empty()) { | ||
| // If there's no payload, create one to make sure the original http status | ||
| // code received is available. | ||
| return Status(status_code, "Received HTTP status code: " + | ||
| std::to_string(http_status_code)); | ||
| 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)); | ||
|
Comment on lines
+159
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
|
||
| } | ||
| auto p = | ||
| ParseJsonError(static_cast<int>(http_status_code), std::move(payload)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks can be combined for better readability. Additionally, it appears
kBadGateway(502) is also expected to be mapped tokUnavailablebased on the test cases (see line 83 ofgoogle/cloud/internal/rest_response_test.cc), but it is currently missing from this function. Consider adding it here.