Marty Thomas
Marty Thomas

Reputation: 857

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

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?

Upvotes: 0

Views: 2160

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219900

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.

Upvotes: 1

Related Questions