nordsoftware/lumen-chained-exception-handler

This package is abandoned and no longer maintained. No replacement package was suggested.

A chained exception handler for the Lumen framework

3.1.0 2022-03-30 12:32 UTC

This package is auto-updated.

Last update: 2023-03-29 00:33:47 UTC


README

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 nordsoftware/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