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 {
$this->someCallThatThrowsAnException();
} catch (NotifiableException $e) {
$e->notify();
// 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 README.md 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.
0 comments:
Post a Comment
Thanks