Skip to content

Commit 360040b

Browse files
author
palPalani
committed
Improved handling invalid payload
1 parent b7a3af4 commit 360040b

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/Sqs/Queue.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Queue\Jobs\SqsJob;
99
use Illuminate\Queue\SqsQueue;
1010
use Illuminate\Support\Facades\Config;
11-
use Illuminate\Support\Facades\Log;
1211
use Illuminate\Support\Str;
1312
use JsonException;
1413
use palPalani\SqsQueueReader\Jobs\DispatcherJob;
@@ -148,22 +147,22 @@ private function modifyMultiplePayload(array | string $payload, string $class):
148147

149148
foreach ($payload as $k => $item) {
150149
try {
151-
$body[$k] = [
152-
'messages' => \json_decode($item['Body'], true, 512, JSON_THROW_ON_ERROR),
153-
'attributes' => $item['Attributes'],
154-
'batchIds' => [
155-
'Id' => $item['MessageId'],
156-
'ReceiptHandle' => $item['ReceiptHandle'],
157-
],
158-
];
159-
$attributes = $item['Attributes'];
160-
$messageId = $item['MessageId'];
161-
$receiptHandle = $item['ReceiptHandle'];
150+
$message = \json_decode($item['Body'], true, 512, JSON_THROW_ON_ERROR);
162151
} catch (JsonException $e) {
163-
Log::warning('Invalid payload!', [$item]);
164-
165-
continue;
152+
$message = [];
166153
}
154+
155+
$body[$k] = [
156+
'messages' => $message,
157+
'attributes' => $item['Attributes'],
158+
'batchIds' => [
159+
'Id' => $item['MessageId'],
160+
'ReceiptHandle' => $item['ReceiptHandle'],
161+
],
162+
];
163+
$attributes = $item['Attributes'];
164+
$messageId = $item['MessageId'];
165+
$receiptHandle = $item['ReceiptHandle'];
167166
}
168167

169168
return [

0 commit comments

Comments
 (0)