From 07faff7d29741bfc06308cb97ba49311fb9c6a15 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 30 May 2023 16:32:46 +0200 Subject: [PATCH] [9.x] Send along value to InvalidPayloadException (#47223) * Send along value to InvalidPayloadException * Update InvalidPayloadException.php --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Queue/InvalidPayloadException.php | 12 +++++++++++- src/Illuminate/Queue/Queue.php | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Queue/InvalidPayloadException.php b/src/Illuminate/Queue/InvalidPayloadException.php index 788fa660db8f..abaf21f508f1 100644 --- a/src/Illuminate/Queue/InvalidPayloadException.php +++ b/src/Illuminate/Queue/InvalidPayloadException.php @@ -6,14 +6,24 @@ class InvalidPayloadException extends InvalidArgumentException { + /** + * The value that failed to decode. + * + * @var mixed + */ + public $value; + /** * Create a new exception instance. * * @param string|null $message + * @param mixed $value * @return void */ - public function __construct($message = null) + public function __construct($message = null, $value = null) { parent::__construct($message ?: json_last_error()); + + $this->value = $value; } } diff --git a/src/Illuminate/Queue/Queue.php b/src/Illuminate/Queue/Queue.php index 4eb87e2a8e4b..03dbbf1b9950 100755 --- a/src/Illuminate/Queue/Queue.php +++ b/src/Illuminate/Queue/Queue.php @@ -102,11 +102,11 @@ protected function createPayload($job, $queue, $data = '') $job = CallQueuedClosure::create($job); } - $payload = json_encode($this->createPayloadArray($job, $queue, $data), \JSON_UNESCAPED_UNICODE); + $payload = json_encode($value = $this->createPayloadArray($job, $queue, $data), \JSON_UNESCAPED_UNICODE); if (json_last_error() !== JSON_ERROR_NONE) { throw new InvalidPayloadException( - 'Unable to JSON encode payload. Error code: '.json_last_error() + 'Unable to JSON encode payload. Error code: '.json_last_error(), $value ); }