Skip to content

Commit

Permalink
[9.x] Send along value to InvalidPayloadException (#47223)
Browse files Browse the repository at this point in the history
* Send along value to InvalidPayloadException

* Update InvalidPayloadException.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
driesvints and taylorotwell authored May 30, 2023
1 parent f43b251 commit 07faff7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/Illuminate/Queue/InvalidPayloadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down

0 comments on commit 07faff7

Please sign in to comment.