Skip to content

Unable to read Exception from Aws\Api\Parser\EventParsingIterator #2994

@Luke-Shepp

Description

@Luke-Shepp

Describe the bug

When parsing an API response, it is structured as an Aws\Api\Parser\EventParsingIterator, and parses each event within the iterator when the current element is fetched.

An event type of error is handled:

if ($event['headers'][':message-type'] === 'error') {
    return $this->parseError($event);
}

However, if the event type is exception, a ParserException is thrown:

if ($event['headers'][':message-type'] !== 'event') {
    throw new ParserException('Failed to parse unknown message type.');
}

It's then, without modification of the library code itself, not possible to retrieve the actual exception details from the response. For example, when dumping the event and stream content before the throw, the actual exception is that the Lambda function failed on this occasion:

Screenshot 2024-09-02 at 12 31 39

Expected Behavior

If there's an exception event, with a JSON payload, it should be decoded and returned - instead of throwing an exception with no way to obtain the actual exception/payload details.

Current Behavior

A ParserException is thrown.

Reproduction Steps

In my specific case,

  • AWS Bedrock Agent configured with an OpenAPI specification
  • Lambda function handling API proxy
  • The API call returns a 500 error, or the lambda function fails
  • ParserException is thrown when trying to extract data from the response.

Possible Solution

Implement a:

if ($event['headers'][':message-type'] === 'exception') {
    return $this->handleException($event);
}

Additional Information/Context

No response

SDK version used

3.306.7, but is the same logic on the main branch

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

php 8.2

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