使用laravel(5.4)我为排队作业设置了一个作业处理程序和一个失败的处理程序。但由于某种原因,当作业失败并且应该调用失败处理程序并将异常传递给它时,我得到了:
[2017-09-04 13:50:31] local.ERROR:Symfony \ Component \ Debug \ Exception \ FatalThrowableError:类型错误:参数1传递给App \ Jobs \ TransferSearchImage :: failed()必须是实例Dompdf \ Exception,给出了GuzzleHttp \ Exception \ ClientException的实例,在/ srv / cr / app / Jobs / TransferSearchImage的第98行的/srv/cr/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php中调用.PHP:91
作业处理函数读取:
/**
* 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);
}
失败的处理函数:
/**
* The job failed to process.
*
* @param Exception $exception
* @return void
*/
public function failed(Exception $exception)
{
// Send user notification of failure, etc...
}
我甚至添加了
使用例外;
上课,但没有变化。也试过前缀\但也没有成功。如何向失败的处理程序提交任何类型的异常?