Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Luke-Shepp opened this issue Sep 2, 2024 · 2 comments
Open
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue queued This issues is on the AWS team's backlog

Comments

@Luke-Shepp
Copy link

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

@Luke-Shepp Luke-Shepp added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2024
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Sep 2, 2024
@yenfryherrerafeliz yenfryherrerafeliz added p2 This is a standard priority issue queued This issues is on the AWS team's backlog and removed needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2024
@adrianpaiva1
Copy link

same issue here

@marcelfolaron
Copy link

Can confirm this issue on our end as well. Debugging was quite difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue queued This issues is on the AWS team's backlog
Projects
None yet
Development

No branches or pull requests

4 participants