@toufik94 try to catch throwable instead of exception.
How to handle exceptions to the user when sending queued notifications?
Hi guys,
Im sending a simple queued notification to my users whenever they try to login. They will receive an email containing a verification code. This all works well, no problems at all.
However, I can't seem to get my head around how to notify users when the job fails. I tried using a try-catch block but that did nothing:
$user = auth()->user();
$user->generateTwoFactorCode();
try {
$user->notify(new TwoFactorCode());
return redirect()->back()->withStatus("Good, it worked!");
} catch (\Exception $e) {
return redirect()->back()->withErrors(["two_factor_code" => "Whoopsie, didnt work!."]);
}
It never catches an exception even though some of these jobs end up in the failed_jobs table.
I also tried using the ''failed' method in the Notification class and Im able to catch the exceptions there, but I cant find a way to send that info to the frontend, which is Blade.
Please or to participate in this conversation.