Skip to content

feat: expose HTTP status code and headers on SDK error classes#319

Open
corvid-agent wants to merge 3 commits intoa2aproject:mainfrom
corvid-agent:fix/expose-http-status-code-in-errors
Open

feat: expose HTTP status code and headers on SDK error classes#319
corvid-agent wants to merge 3 commits intoa2aproject:mainfrom
corvid-agent:fix/expose-http-status-code-in-errors

Conversation

@corvid-agent
Copy link
Copy Markdown
Contributor

Summary

  • Adds optional statusCode and headers properties to all A2A SDK error classes (TaskNotFoundError, TaskNotCancelableError, PushNotificationNotSupportedError, UnsupportedOperationError, ContentTypeNotSupportedError, InvalidAgentResponseError, AuthenticatedExtendedCardNotConfiguredError) so that consumers can implement HTTP-aware error handling.
  • Updates the REST transport (RestTransport) to extract HTTP status code and response headers from the Response object and pass them through when constructing error instances via mapToError.
  • Exports the new A2AErrorHttpDetails interface from the client entry point for use by consumers.
  • Adds comprehensive tests covering all error types, verifying that statusCode and headers are correctly populated on errors thrown by the REST transport.

Closes #317

Test plan

  • All 414 existing tests pass (no regressions)
  • New tests verify statusCode is set on TaskNotFoundError (404), TaskNotCancelableError (409), PushNotificationNotSupportedError (400), UnsupportedOperationError (405), ContentTypeNotSupportedError (415), InvalidAgentResponseError (502), and AuthenticatedExtendedCardNotConfiguredError (401)
  • New test verifies that response headers (e.g. Retry-After, X-RateLimit-Remaining) are available on errors for rate-limiting / backoff strategies
  • Backward compatibility verified: constructor changes are additive (second parameter is optional), so existing code including JSON-RPC error subclasses continues to work without modification
  • TypeScript lint passes with no new errors

🤖 Generated with Claude Code

@corvid-agent corvid-agent requested a review from a team as a code owner February 9, 2026 21:39
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @corvid-agent, 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 significantly improves the error handling capabilities of the A2A SDK by exposing underlying HTTP details directly within SDK error classes. This change empowers developers to build more robust and responsive applications by enabling them to react to specific HTTP status codes and headers, such as implementing retry logic based on Retry-After headers, directly from caught SDK errors. The modifications are backward-compatible, ensuring existing integrations remain unaffected.

Highlights

  • Enhanced Error Classes: SDK error classes now include optional statusCode and headers properties, enabling more granular HTTP-aware error handling for consumers.
  • REST Transport Integration: The RestTransport has been updated to extract HTTP status codes and response headers from Response objects and populate these new properties on thrown errors.
  • New Interface Export: The A2AErrorHttpDetails interface is now exported from the client entry point, allowing consumers to type and leverage the new error details.
  • Comprehensive Testing: New tests confirm the correct population of statusCode and headers across all relevant error types and scenarios, including specific rate-limiting headers.
Changelog
  • src/client/index.ts
    • Exports the new A2AErrorHttpDetails interface.
  • src/client/transports/rest_transport.ts
    • Introduces a new static method extractHttpDetails to parse HTTP status code and headers from a Response object.
    • Modifies the _handleErrorResponse method to utilize extractHttpDetails and pass the extracted HTTP details to the mapToError function.
    • Updates the mapToError function to accept and forward the HTTP details to the constructors of various A2A error classes.
  • src/errors.ts
    • Defines the A2AErrorHttpDetails interface, specifying statusCode and headers properties.
    • Extends all A2A SDK error classes (e.g., TaskNotFoundError, TaskNotCancelableError) by adding statusCode and headers properties and updating their constructors to accept and assign these optional HTTP details.
  • test/client/transports/rest_transport.spec.ts
    • Adds new test cases to verify that statusCode is correctly set for TaskNotFoundError (404), TaskNotCancelableError (409), PushNotificationNotSupportedError (400), UnsupportedOperationError (405), ContentTypeNotSupportedError (415), InvalidAgentResponseError (502), and AuthenticatedExtendedCardNotConfiguredError (401).
    • Includes a test to confirm that custom response headers like Retry-After and X-RateLimit-Remaining are correctly captured and available on the error object.
Activity
  • The author has added new functionality to expose HTTP status codes and headers on SDK error classes.
  • The RestTransport has been updated to correctly populate these new error properties.
  • Comprehensive unit tests have been introduced to validate the correct behavior across all affected error types and header scenarios.
  • Backward compatibility has been explicitly verified, ensuring no regressions for existing code.
  • TypeScript linting has been confirmed to pass without new errors.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 9, 2026

🧪 Code Coverage

⬇️ Download Full Report

Main PR Delta
src/client/transports/rest_transport.ts 85.8% 87.41% 🟢 +1.61%
src/errors.ts 78.57% 100% 🟢 +21.43%
Total 80.22% 80.68% 🟢 +0.46%

Generated by coverage-comment.yml

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 is a great enhancement, exposing HTTP status codes and headers on SDK errors. This will be very useful for consumers to build more robust error handling, for example for rate limiting. The implementation is solid and comes with a comprehensive set of tests.

I've left a couple of suggestions for improvement:

  • In src/client/transports/rest_transport.ts, I've suggested a more concise way to convert response headers to an object using Object.fromEntries.
  • Regarding src/errors.ts, while the suggestion to introduce a base error class for better maintainability is excellent, we'll defer this refactoring to a future major release to avoid potential breaking changes to the public SDK error interface, as per repository guidelines. A TODO will be added to track this.

Overall, this is a well-executed feature. Addressing the immediate feedback will further improve the code quality.

Comment on lines +343 to +347
const headers: Record<string, string> = {};
response.headers.forEach((value, key) => {
headers[key] = value;
});
return { statusCode: response.status, headers };
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.

medium

The logic for converting the Headers object to a plain JavaScript object can be simplified. The Headers object is iterable, so you can use Object.fromEntries() for a more concise implementation.

Suggested change
const headers: Record<string, string> = {};
response.headers.forEach((value, key) => {
headers[key] = value;
});
return { statusCode: response.status, headers };
return {
statusCode: response.status,
headers: Object.fromEntries(response.headers),
};

corvid-agent and others added 3 commits February 12, 2026 22:18
Add optional `statusCode` and `headers` properties to all A2A SDK error
classes (TaskNotFoundError, TaskNotCancelableError, etc.) so that
consumers can implement HTTP-aware error handling (e.g. distinguishing
401 from 404 from 429). The REST transport now populates these fields
from the HTTP response when mapping errors.

Closes a2aproject#317

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address review feedback: simplify headers extraction by using
Object.fromEntries() instead of manual forEach loop.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@corvid-agent corvid-agent force-pushed the fix/expose-http-status-code-in-errors branch from 8e82038 to 0be73a4 Compare February 13, 2026 05:18
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.

[Feat]: Passthrough http status code in error

1 participant