aws icon indicating copy to clipboard operation
aws copied to clipboard

Could not parse response as array

Open rodion-k opened this issue 2 months ago • 1 comments

I'm using Symfony Messenger with amazon-sqs-transport and sometimes I get the following exceptions:

AsyncAws\Core\Exception\UnparsableResponse: Could not parse response as array

Stack Trace:
1. Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::__destruct()
   File: /var/www/EmmaCare/vendor/symfony/amazon-sqs-messenger/Transport/Connection.php:82
   Line: $this->reset();

2. Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::reset()
   File: /var/www/EmmaCare/vendor/symfony/amazon-sqs-messenger/Transport/Connection.php:374
   Line: if (!$this->fetchMessage()) {

3. Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::fetchMessage()
   File: /var/www/EmmaCare/vendor/symfony/amazon-sqs-messenger/Transport/Connection.php:237
   Line: foreach ($this->currentResponse->getMessages() as $message) {

4. AsyncAws\Sqs\Result\ReceiveMessageResult::getMessages()
   File: /var/www/EmmaCare/vendor/async-aws/sqs/src/Result/ReceiveMessageResult.php:28
   Line: $this->initialize();

5. AsyncAws\Core\Result::initialize()
   File: /var/www/EmmaCare/vendor/async-aws/core/src/Result.php:139
   Line: $this->populateResult($this->response);

6. AsyncAws\Sqs\Result\ReceiveMessageResult::populateResult()
   File: /var/www/EmmaCare/vendor/async-aws/sqs/src/Result/ReceiveMessageResult.php:35
   Line: $data = $response->toArray();

7. AsyncAws\Core\Response::toArray()
   File: /var/www/EmmaCare/vendor/async-aws/core/src/Response.php:353
   Line: throw new UnparsableResponse('Could not parse response as array', 0, $e);
Symfony\Component\HttpClient\Exception\JsonException: Response body is empty.

Stack Trace:
1. Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::__destruct()
   File: /var/www/EmmaCare/vendor/symfony/amazon-sqs-messenger/Transport/Connection.php:82
   Line: $this->reset();

2. Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::reset()
   File: /var/www/EmmaCare/vendor/symfony/amazon-sqs-messenger/Transport/Connection.php:374
   Line: if (!$this->fetchMessage()) {

3. Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection::fetchMessage()
   File: /var/www/EmmaCare/vendor/symfony/amazon-sqs-messenger/Transport/Connection.php:237
   Line: foreach ($this->currentResponse->getMessages() as $message) {

4. AsyncAws\Sqs\Result\ReceiveMessageResult::getMessages()
   File: /var/www/EmmaCare/vendor/async-aws/sqs/src/Result/ReceiveMessageResult.php:28
   Line: $this->initialize();

5. AsyncAws\Core\Result::initialize()
   File: /var/www/EmmaCare/vendor/async-aws/core/src/Result.php:139
   Line: $this->populateResult($this->response);

6. AsyncAws\Sqs\Result\ReceiveMessageResult::populateResult()
   File: /var/www/EmmaCare/vendor/async-aws/sqs/src/Result/ReceiveMessageResult.php:35
   Line: $data = $response->toArray();

7. AsyncAws\Core\Response::toArray()
   File: /var/www/EmmaCare/vendor/async-aws/core/src/Response.php:351
   Line: return $this->httpResponse->toArray(false);

8. Symfony\Component\HttpClient\Response\AsyncResponse::toArray()
   File: /var/www/EmmaCare/vendor/symfony/http-client/Response/CommonResponseTrait.php:84
   Line: throw new JsonException('Response body is empty.');

I don't have a way to reproduce it, but I'm wondering why throw: false is used here. I guess AWS returns some error here with an empty body, and it would be useful to see at least the http code.

rodion-k avatar Sep 30 '25 16:09 rodion-k