Skip to content

When using streaming response mode, exceptions do not include the message text from the HTTP body #3124

@glennschmidt

Description

@glennschmidt

Describe the bug

When making a request which uses ['@http' => ['stream' => true]], if the server returns a HTTP error status such as 400, the SDK is unable to read the response body for inclusion in the exception message, and consequently there's no way to see the reason for the error.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The PHP exception should include the error message from the HTTP body, as in non-streaming mode.

Fatal error: Uncaught exception 'Aws\BedrockRuntime\Exception\BedrockRuntimeException' with message 'Error executing "ConverseStream" on "https://bedrock-runtime.us-west-2.amazonaws.com/model/x/converse-stream"; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-west-2.amazonaws.com/model/x/converse-stream` resulted in a `400 Bad Request` response:
{"message":"The provided model identifier is invalid."}

Current Behavior

The PHP exception says Unable to parse error information from response.

Fatal error: Uncaught exception 'Aws\BedrockRuntime\Exception\BedrockRuntimeException' with message 'Error executing "ConverseStream" on "https://bedrock-runtime.us-west-2.amazonaws.com/model/x/converse-stream"; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-west-2.amazonaws.com/model/x/converse-stream` resulted in a `400 Bad Request` response Unable to parse error information from response - Error parsing JSON: Syntax error'

Reproduction Steps

Make a streaming API call, with some invalid parameters so that it would cause a 400 Bad Request response.

$client = new Aws\BedrockRuntime\BedrockRuntimeClient([
    'version' => '2023-09-30',
    'region' => 'us-west-2',
]);

$client->converseStream([
    'modelId' => 'x',
    '@http' => [
        'stream' => true,
    ],
]);

Possible Solution

This could be because the response body stream is non-seekable, and some other part of the SDK has already read it.

Additional Information/Context

No response

SDK version used

3.343.14

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 8.1.31, Linux

Metadata

Metadata

Labels

bugThis issue is a bug.p2This is a standard priority issuequeuedThis issues is on the AWS team's backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions