Skip to content

feat(error): surface retry-after header#809

Open
Lubrsy706 wants to merge 3 commits into
googleworkspace:mainfrom
Lubrsy706:feat/error-retry-after
Open

feat(error): surface retry-after header#809
Lubrsy706 wants to merge 3 commits into
googleworkspace:mainfrom
Lubrsy706:feat/error-retry-after

Conversation

@Lubrsy706
Copy link
Copy Markdown

Summary

  • Parse Retry-After response headers from failed Google API responses
  • Include retry_after_seconds in structured API errors when Google returns either delta seconds or an HTTP-date
  • Preserve existing errors without the field when no retry hint is present

Fixes #777

Tests

  • cargo fmt --check
  • cargo test -p google-workspace test_error_to_json_retry_after_seconds
  • cargo test -p google-workspace-cli test_handle_error_response_includes_retry_after
  • cargo test -p google-workspace-cli retry_after_seconds
  • cargo check -p google-workspace-cli
  • git diff --check

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

⚠️ No Changeset found

Latest commit: 542eddb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the error handling capabilities of the Google Workspace CLI by surfacing 'Retry-After' headers from failed API requests. By parsing these headers into a structured format, the application can now provide clearer guidance on when to retry operations, particularly in rate-limiting scenarios.

Highlights

  • Retry-After Header Parsing: Implemented logic to parse the 'Retry-After' header from Google API responses, supporting both delta seconds and HTTP-date formats.
  • Structured Error Updates: Added 'retry_after_seconds' to the 'GwsError::Api' variant to propagate retry information in structured API errors.
  • API Integration: Updated the API executor to extract and pass the 'Retry-After' value when handling error responses.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@googleworkspace-bot googleworkspace-bot added area: http area: core Core CLI parsing, commands, error handling, utilities crate: google-workspace labels May 15, 2026
Copy link
Copy Markdown
Contributor

@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 adds support for the Retry-After header by introducing a retry_after_seconds field to the GwsError::Api error variant and implementing parsing logic in the executor for both numeric and date-based header values. Review feedback points out that using local system time to calculate retry delays from HTTP-dates is prone to clock skew; it is suggested to use the response's Date header as the reference time to comply with RFC 7231 and ensure accurate retry intervals.

.headers()
.get(RETRY_AFTER)
.and_then(|value| value.to_str().ok())
.and_then(|value| parse_retry_after_seconds(value, SystemTime::now()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Calculating the retry delay using SystemTime::now() is susceptible to clock skew between the client and the server. Per RFC 7231 Section 7.1.1.2, the recipient SHOULD use the value of the Date header field from the response as the reference time for calculating delta-seconds from an HTTP-date. If the client's clock is significantly ahead of the server's, this calculation could result in a 0 delay, leading to immediate retries that continue to fail.

@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
Contributor

@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 support for the Retry-After HTTP header in API error responses. It adds a retry_after_seconds field to the GwsError::Api error variant and implements logic in the executor to parse this header from both delta-seconds and HTTP-date formats. While the field is correctly integrated into the JSON output and error handling logic, feedback indicates that the Display implementation for GwsError::Api should be updated to include the retry hint to improve the usability of the CLI terminal output.

/// For `accessNotConfigured` errors: the GCP console URL to enable the API.
enable_url: Option<String>,
/// Seconds to wait before retrying, when the API returned a Retry-After header.
retry_after_seconds: Option<u64>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While the field is correctly added to the JSON output, it is currently missing from the human-readable Display implementation for GwsError::Api (line 22).

For a CLI tool, surfacing the retry hint in the terminal output (e.g., error[api]: Rate limit exceeded (retry after 17s)) is critical for usability. Consider updating the Display implementation to include this information when available.

@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
Contributor

@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 support for the Retry-After HTTP header in API error responses. The GwsError::Api error variant has been updated to include an optional retry_after_seconds field, which is now populated during request execution by parsing the Retry-After header (supporting both integer seconds and HTTP-date formats). The error's string representation and JSON output have also been updated to include this retry information, and all relevant call sites and tests have been adjusted accordingly. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities area: http crate: google-workspace

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surface Retry-After header in error envelope for rate-limited responses

2 participants