Skip to content

fix: Setting the proper content type for errors.#720

Merged
kabir merged 1 commit intoa2aproject:mainfrom
ehsavoie:issue_719
Mar 10, 2026
Merged

fix: Setting the proper content type for errors.#720
kabir merged 1 commit intoa2aproject:mainfrom
ehsavoie:issue_719

Conversation

@ehsavoie
Copy link
Collaborator

The expected content type is application/problem+json when there is an error and not application/json

Fixes #719 🦕

@gemini-code-assist
Copy link
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 refines the API's error handling by ensuring that all error responses consistently use the application/problem+json content type, providing a standardized and machine-readable format for problem details. It also improves the serialization of successful JSON responses and expands test coverage to validate these content type changes across the application's various communication protocols.

Highlights

  • Standardized Error Content Type: The Content-Type header for error responses has been updated from application/json to application/problem+json across both JSON-RPC and REST endpoints, aligning with RFC 7807 for problem details.
  • Conditional Content Type for JSON-RPC: For JSON-RPC non-streaming responses, the Content-Type is now dynamically set to application/problem+json if an error is present, otherwise it remains application/json for successful responses.
  • Improved JSON Serialization: The JSON serialization logic for success responses in the REST handler was updated to use alwaysPrintFieldsWithNoPresence() for JsonFormat.printer(), ensuring all fields, including those with default values, are explicitly present.
  • Enhanced Test Coverage: Existing tests were updated to assert the correct Content-Type for both success and error responses, and new tests were added to specifically verify application/problem+json for JSON parsing and method not found errors in JSON-RPC.
Changelog
  • reference/jsonrpc/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java
    • Introduced a constant JSON_ERROR_CONTENT_TYPE for application/problem+json.
    • Updated the Content-Type header for direct error responses to application/problem+json.
    • Modified the Content-Type header for non-streaming responses to be application/problem+json if an error is present, otherwise application/json.
  • reference/jsonrpc/src/test/java/io/a2a/server/apps/quarkus/A2AServerRoutesTest.java
    • Added static imports for CONTENT_TYPE and APPLICATION_JSON.
    • Introduced a constant JSON_ERROR_CONTENT_TYPE for application/problem+json.
    • Added verify statements to several existing tests to assert that the Content-Type header is application/json for successful responses.
    • Added two new test cases (testJsonParseError_ContentTypeIsProblemJson and testMethodNotFound_ContentTypeIsProblemJson) to specifically verify that error responses have a Content-Type of application/problem+json.
  • transport/rest/src/main/java/io/a2a/transport/rest/handler/RestHandler.java
    • Introduced constants JSON_ERROR_CONTENT_TYPE and JSON_CONTENT_TYPE.
    • Updated HTTPRestResponse creation in deleteTaskPushNotificationConfiguration, createSuccessResponse, createErrorResponse, getExtendedAgentCard, and getAgentCard to use the new content type constants.
    • Changed JsonFormat.printer().includingDefaultValueFields() to JsonFormat.printer().alwaysPrintFieldsWithNoPresence() in createSuccessResponse.
  • transport/rest/src/test/java/io/a2a/transport/rest/handler/RestHandlerTest.java
    • Modified numerous test assertions to verify that error responses now return application/problem+json as their Content-Type instead of application/json.
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.

Copy link
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 correctly updates the content type for error responses to "application/problem+json" across both JSON-RPC and REST handlers, with updated tests reflecting these changes. However, a critical security issue was identified in the REST transport: error response bodies are constructed using manual string concatenation, which could lead to JSON injection vulnerabilities. It is strongly recommended to use a proper JSON library for serialization to ensure all output is correctly escaped. Additionally, I've provided suggestions to improve code quality by reducing constant duplication, leveraging standard library constants, and enhancing test robustness by adjusting constant visibility.

The expected content type is application/problem+json when there is an error and not application/json

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@ehsavoie ehsavoie added this to the 1.0.0 milestone Mar 10, 2026
@kabir kabir merged commit 14fece4 into a2aproject:main Mar 10, 2026
11 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.

[Bug]: Wrong content-type for JSONRPC and REST error

3 participants