What You’ll Learn
Why exception notification needs rate-limiting
The Cache::add() deduplication pattern
Building the ErrorReporter static service
The ExceptionOccurred Mailable with full context
Wiring into Laravel’s exception handler
Sensitive field masking
The Problem with Naive Exception Emails
If you wire a simple exception email into bootstrap/app.php like this:
$exceptions -> report ( function ( Throwable $e ) : void { Mail :: to ( '[email protected]' ) -> send ( new ExceptionOccurred ( $e ) ) ; } ) ;
Enter fullscreen mode
Exit fullscreen mode
One runtime error – say, a database timeout during a traffic spike – fires that email 300 times per minute. Your inbox is flooded. The mail queue backs up. The server’s mail rate limit kicks in.…