Skip to content

impl(rest): map http code 504 to kUnavailable#16077

Merged
scotthart merged 1 commit intogoogleapis:mainfrom
scotthart:rest_http_status_code_504
Apr 13, 2026
Merged

impl(rest): map http code 504 to kUnavailable#16077
scotthart merged 1 commit intogoogleapis:mainfrom
scotthart:rest_http_status_code_504

Conversation

@scotthart
Copy link
Copy Markdown
Member

Upcoming RAB feature considers 504 retryable. Additionally, improve returned error status when no payload is available.

@scotthart scotthart requested a review from a team as a code owner April 10, 2026 22:19
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 120 to +125
if (code == HttpStatusCode::kServiceUnavailable) {
return StatusCode::kUnavailable;
}
if (code == HttpStatusCode::kGatewayTimeout) {
return StatusCode::kUnavailable;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
  }

Comment on lines +159 to +164
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));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. When passing a local object to a method that takes it by value, use std::move to avoid unnecessary copies.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (7bc7f71) to head (39cd67c).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@scotthart scotthart enabled auto-merge (squash) April 13, 2026 14:34
@scotthart scotthart merged commit efaacf4 into googleapis:main Apr 13, 2026
53 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants