Send Notifications for Exceptions with the Notifiable Exception Package


October 14th, 2019

Send Notifications for Exceptions with the Notifiable Exception Package

Notifiable Exception is a Laravel package by Andrea Marco Sartori to send notifications for certain exceptions. For exceptions to be notifiable, they need to implement the package’s Notifiable interface and use the Notifies trait. Here’s an example from the project’s readme:

use Cerbero\NotifiableException\Notifiable;
use Cerbero\NotifiableException\Notifies;
use Exception;
class UrgentException extends Exception implements Notifiable
use Notifies;

You can also extend the NotifiableException class from the package if you don’t need to extend any particular exception class.

If you don’t catch notifiable exceptions they will be notified automatically. However, you can have granular control when using a try/catch:

try {
} catch (NotifiableException $e) {
// exception handling logic

This package is capable of other interesting things like customizing the notification channels for a specific exception class and customizing the message per channel. Check out the package’s for full details.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at cerbero90/notifiable-exception.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.