Skip to content

lupferjoel/lumen-chained-exception-handler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lumen-chained-exception-handler

GitHub Actions status Scrutinizer Code Quality Coverage Status Code Climate

This utility allows you to chain together multiple exception handlers in your Lumen application. This can be useful if you want to use the rendering capabilities of the default exception handler, but you want to use the reporting logic from a third-party exception handler. The reporting logic can usually be extended by adding another Monolog handler, but all exceptions will be mangled into strings which is not always feasible.

Installation

Run the following command to install the package through Composer:

composer require lupferjoel/lumen-chained-exception-handler

Usage

Replace the $app->singleton() call which registers the concrete exception handler in bootstrap/app.php with the following:

$app->instance(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    new Nord\Lumen\ChainedExceptionHandler\ChainedExceptionhandler(
        new App\Exceptions\Handler()
    )
);

The constructor takes two parameters, a primary exception handler and an optional array of secondary handlers. The report() method will be called on all handlers, but the render() and renderForConsole() methods will only be called on the primary handler.

For example, if want to use the default Laravel\Lumen\Exceptions\Handler as your primary error handler and Foo\Bar\ExceptionHandler and Baz\ExceptionHandler as secondary exception handlers, you would use this:

$app->instance(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    new Nord\Lumen\ChainedExceptionHandler\ChainedExceptionhandler(
        new Laravel\Lumen\Exceptions\Handler(),
        [new Foo\Bar\ExceptionHandler(), new Baz\ExceptionHandler()]
    )
);

Running tests

Clone the project and install its dependencies by running:

composer install

Run the following command to run the test suite:

vendor/bin/phpunit

License

See LICENSE

About

A chained exception handler for the Lumen framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%