desarrolla2/mail-exception-bundle
KernelEvents::EXCEPTION and Mailer components, which are not natively available in Laravel. Laravel uses Illuminate\Foundation\Events\ExceptionOccurred and its own Mail facade, requiring a custom abstraction layer to replicate functionality.ExceptionListener would need replacement with Laravel’s App\Exceptions\Handler or a service provider listening to ExceptionOccurred.config.yml would need migration to Laravel’s config/exception.php or environment variables, adding refactoring overhead.App\Exceptions\Handler for exception interception.Mail facade for email delivery.app()->environment().NotFoundHttpException) would require custom logic in Laravel, as the bundle’s avoid.exceptions config is Symfony-specific.Mailer component may conflict with Laravel’s native swiftmailer or php-mailer, requiring dependency resolution or isolation.App\Exceptions\Handler and Mail facade to avoid Symfony dependencies entirely.avoid.environments) to Laravel’s config/exception.php or .env.ExceptionEmail class meet needs?)report() vs. render()), and will it conflict with other error handlers?ExceptionEmail would need redaction logic if needed.)App\Exceptions\Handler (overrides report() and render()).Mail facade or Notification system.app()->environment() or .env variables.ExceptionOccurred event for dynamic filtering.ExceptionHandler Extension: A lightweight alternative with zero external dependencies.App\Exceptions\Handler:
report() to send emails for uncaught exceptions.// app/Exceptions/Handler.php
use Illuminate\Support\Facades\Mail;
use App\Mail\ExceptionEmail;
public function report(Throwable $exception)
{
if ($this->shouldSendExceptionEmail($exception)) {
Mail::to(config('mail-exception.to'))
->send(new ExceptionEmail($exception));
}
parent::report($exception);
}
protected function shouldSendExceptionEmail(Throwable $exception): bool
{
$ignoredEnvironments = config('mail-exception.avoid.environments', []);
$ignoredExceptions = config('mail-exception.avoid.exceptions', []);
return !in_array(app()->environment(), $ignoredEnvironments)
&& !in_array(get_class($exception), $ignoredExceptions);
}
ExceptionEmail Mailable:
// app/Mail/ExceptionEmail.php
public function build()
{
return $this->subject(config('mail-exception.subject'))
->view('emails.exception', [
'exception' => $this->exception,
'request' => request()->all(),
]);
}
config/app.php or .env:
// config/exception.php
return [
'mail-exception' => [
'from' => 'errors@example.com',
'to' => 'team@example.com',
'subject' => 'Production Exception Alert',
'avoid' => [
'environments' => ['local', 'testing'],
'exceptions' => [
'Symfony\Component\HttpKernel\Exception\NotFoundHttpException',
'Illuminate\Routing\Exceptions\UrlNotFoundException',
],
],
],
];
resources/views/emails/exception.blade.php to mirror the bundle’s email format.ExceptionOccurred and send emails.// app/Providers/MailExceptionServiceProvider.php
public function boot()
{
Event::listen(ExceptionOccurred::class, function ($event) {
if (!$this->shouldSend($event->exception)) {
return;
}
Mail::to(config('mail-exception.to'))
->send(new ExceptionEmail($event->exception));
});
}
config/app.php under providers.laravel-mail-exception).Mailer, ensure no conflicts with Laravel’s swiftmailer (use composer require symfony/mailer cautiously or isolate dependencies)..env can replace Symfony’s config.yml for avoid.environments.avoid.exceptions would need mapping to Laravel’s exception classes (e.g., Symfony\Component\HttpKernel\Exception\NotFoundHttpException → Illuminate\Routing\Exceptions\UrlNotFoundException).App\Exceptions\Handler with email alerts.avoid.environments and avoid.exceptions logic.Mail or ExceptionHandler may require occasional adjustments.How can I help you explore Laravel packages today?