0

使用 Laravel 5.1 的队列,当作业失败时我会抛出异常。

throw new \Exception('No luck');

正如 Laravel 在处理失败的作业时建议的那样,我正在“捕捉” 中的异常AppServiceProvider,并使用它向我们的团队发送电子邮件。

public function boot()
{
    Queue::failing(function ($connection, $job, $data) {
        $info['data'] = $data;
        \Mail::send('emails.jobs.failed', $info, function($message) {
            $message->to('test@email.com')->subject('Job failed');
        });
    });
}

在电子邮件中,我想放置异常消息(在本例中为“不走运。”)。但我不知道如何将它传递给 Queue::failing()。

有任何想法吗?

4

1 回答 1

1

调用失败的回调后,Laravel 重新抛出异常

看来,如果您真的需要错误消息,则必须自己捕获异常。

于 2015-11-17T18:29:27.653 回答