-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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:
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
ParserExceptionis 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