Skip to content

[Bug]: A2A Client incorrectly handles HTTP error responses when using streaming mode #502

@efunneko

Description

@efunneko

What happened?

Summary

The client side code incorrectly handles HTTP error responses when using streaming mode. Instead of
surfacing the actual HTTP status code and error message, the SDK attempts to parse error
responses as Server-Sent Events (SSE) and reports an SSE protocol error.

For example, an authentication failure (401) gives this exception:

HTTP Error 400: Invalid SSE response or protocol error: Expected response header Content-Type to 
contain 'text/event-stream', got 'application/json'    

Environment

• Component: A2A Python SDK (0.3.7)
• Affected Module: a2a.client.base_client
• Transport: JSON-RPC over HTTP with SSE streaming

Expected Behavior

When an A2A agent returns an HTTP error response (e.g., 500, 503, 401, 404):

1 SDK detects the non-2xx HTTP status code
2 SDK reads the error response body
3 SDK raises A2AClientHTTPError with the actual status code and error message

Example:

A2AClientHTTPError: HTTP 500 - Internal Server Error: Database connection failed                 

Actual Behavior

The SDK attempts to parse all responses as SSE streams, regardless of HTTP status code:

1 SDK tries to parse response as text/event-stream
2 SDK encounters Content-Type: application/json (typical for error responses)
3 SDK raises an SSE protocol error with status 400
4 The actual HTTP status code is lost

Example:

HTTP Error 400: Invalid SSE response or protocol error: Expected response header Content-Type to 
contain 'text/event-stream', got 'application/json'                                              

Impact

• Lost Error Information: Actual HTTP status codes and error messages are completely lost
• Misleading Errors: All HTTP errors appear as "400 Bad Request"
• Can't properly deal with expired tokens for oauth
• Broken Retry Logic: Cannot distinguish between transient (503) and permanent (500) errors
• Difficult Debugging: Impossible to diagnose downstream agent failures

Affected Scenarios

This affects all HTTP error responses in streaming mode, including:

• 500 Internal Server Error
• 503 Service Unavailable
• 401 Unauthorized
• 404 Not Found
• Any other 4xx or 5xx status code

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions