Using laravel (5.4) I set up a job handler and a failed handler for queued jobs. But for some reason when the job fails and the fail handler should be called and the exception passed to it, I am getting:
[2017-09-04 13:50:31] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to App\Jobs\TransferSearchImage::failed() must be an instance of Dompdf\Exception, instance of GuzzleHttp\Exception\ClientException given, called in /srv/cr/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php on line 98 in /srv/cr/app/Jobs/TransferSearchImage.php:91
The job handler function reads:
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->logFunction();
// get and build token
$apiTokenType = 'Bearer';
$apiTokenCode = env('SEARCH_API_KEY');
$apiToken = $apiTokenType . ' ' . $apiTokenCode;
// get uri
$uri = env('SEARCH_TRANSFER_URI') . 'a';
Log::Debug('apiToken: ' . $apiToken);
Log::Debug('searchid: ' . $this->transferData['searchid']);
Log::Debug('base64: ' . $this->transferData['base64']);
// build headers
$headers = [
'Authorization' => $apiToken,
'Content-Type' => 'application/json',
'Accept-Encoding' => 'application/json',
'X-Requested-With' => 'XMLHttpRequest'
];
// encode data for body
$body = \GuzzleHttp\json_encode($this->transferData);
// make request
$client = new \GuzzleHttp\Client;
$request = new \GuzzleHttp\Psr7\Request('POST', $uri, $headers, $body);
$response = $client->send($request, ['timeout' => 10]);
$status = $response->getStatusCode();
$data = json_decode( (string) $response->getBody() );
Log::Debug('status: ' . $status);
}
And the failed handler function:
/**
* The job failed to process.
*
* @param Exception $exception
* @return void
*/
public function failed(Exception $exception)
{
// Send user notification of failure, etc...
}
I even added
use Exception;
to the class but no change. Also tried prefixing a \ but no success either. How can I submit any kind of Exception to the failed handler?