Andrea Marco Sartori
Andrea Marco Sartori

Reputation: 305

Laravel 5 - Add exceptions rendering logic from a package

I'm developing a package for Laravel 5 and I'd like to add the rendering logic of my own exceptions to the default ExceptionHandler.

I don't want to replace the default Laravel 5 exception handler, just want to let the application where my package is installed be aware of how my package exceptions should be rendered.

How can I do that? Thank you :)

Upvotes: 3

Views: 538

Answers (1)

Dwight
Dwight

Reputation: 12470

If you wanted to replace the application exception handler, you could do so in your service provider. While it might be nice to extend from the application exception handler it would be difficult because it might not be named App\Excpetions\Handler if the developers have changed the application namespace.

$app->singleton(
    'Illuminate\Contracts\Debug\ExceptionHandler',
    'Vendor\Package\ExceptionHandler'
);

Otherwise, you might consider providing a trait that a developer can pull into their own ExceptionHandler and leverage your additional functionality that way.

Upvotes: 2

Related Questions