doudi2229 2017-09-04 14:04
浏览 31

Laravel - 例外必须是dompdf的一个实例

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大