Passing Exception Message to Queue::failing() in Laravel 5.1?

2.1k Views Asked by At

Using Laravel 5.1's Queues, I'm throwing an exception when a job fails.

throw new \Exception('No luck');

As Laravel recommends when dealing with failed jobs, I'm "catching" the exception in the AppServiceProvider, and using that to send our team an email.

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

Within the email, I would like to place the exception's message (in this case "No luck."). But I can't figure out how to pass that along to Queue::failing().

Any ideas?

1

There are 1 best solutions below

5
Joseph Silber On

After calling the failing callback, Laravel rethrows the exception.

It seems if you really need the error message, you'll have to catch the exception yourself.