-
Notifications
You must be signed in to change notification settings - Fork 11.3k
[12.x] Dispatch NotificationFailed when sending fails #55507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Notice, that some channel transports already dispatches this event, appending to it some transport specific context. If |
@taylorotwell should I move the try/catch to each built-in channel/transport? |
I see from the repos within the https://github.com/search?q=org%3Alaravel-notification-channels%20NotificationFailed&type=code While the ones which choose to dispatch a https://github.com/search?q=org%3Alaravel-notification-channels%20NotificationSent&type=code Although I would expect 3rd-party packages to dispatch their own events, I understand some of these packages are relying on this behavior for some time and changing this would be cumbersome for users relying on that behavior. Maybe we can think of a solution to somehow throttle the framework's Perhaps registering a listener that shares some state with the But ideally, I believe the best would be to cooperate with 3rd-party packages and ask them to dispatch their own namespaced events. The reasoning for my stance, is that monitoring tools like Such is that currently |
As noted on comment: Some community maintained channels already dispatch the I believe it would be better if 3rd-party packages dispatched their own namespaced events, instead. But considering some of these packages are doing this for some time already, I updated the PR to add a mechanism to prevent double dispatching the event. I updated the PR's description with these changes. On Laravel 13.x we could remove this hackish guard, and add a note on the upgrade guide asking 3rd-party packages to move to use their own namespaced events. |
Excuse me, @rodrigopedra, but what if we have multichannel notification and few channels fail? I think it would be better to prevent event duplication per channel (driver). |
@Cellard, the guard only affects the top-level It won't affect any channels already dispatching the event by themselves. Let's say that inside the try block, 3 channels send a Also, on the changes proposed here, the In a multichannel scenario, if an exception is thrown and not handled by a channel transport, it would already prevent, by the nature of an exception halting execution, other events to be dispatched by other channels, right? The idea is not to deduplicate events channels already dispatch. Specially, as you pointed out in your comment, some channels might be adding their own data to the event's last parameter. The guard was added to assure any previous behavior, regarding the The idea of the last changes is to prevent an additional |
Closed by mistake when syncing my local branch |
Closes #55479
As noted on issue #55479, the
Illuminate\Notifications\Events\NotificationFailed
is never dispatched by the framework.There is also a
TODO
comment onlaravel/nighwatch
about this:https://github.com/laravel/nightwatch/blob/7cdfc295f71619fde964b45662237f71e3c7559b/src/Sensors/NotificationSensor.php#L68
As noted on this comment on issue #55479:
#55479 (comment)
Some community provided channels are already dispatching the
Illuminate\Notifications\Events\NotificationFailed
on their own.A listener was added to prevent this event being double dispatched.
This PR:
try/catch
block to theIlluminate\Notifications\NotificationSender@sendToNotifiable()
method, so theNotificationFailed
event is dispatched if an exception is thrown when sending a notificationNotificationFailed
event to prevent double dispatching this event to users