charm/exception-middleware

Provides a PSR-15 Middleware which traps exceptions and renders a nice error page.

1.0.0 2022-03-04 12:06 UTC

This package is auto-updated.

Last update: 2024-11-04 17:54:00 UTC


README

A simple middleware implementation that catches exceptions thrown later in the exception stack and renders a nice error message.

Configuration

$middleware = new ExceptionMiddleware([
    'error_handler' => function(\Throwable $e) {
        if ($e->getCode() === 404) {
            return render_page_not_found();
        }
        // If error handler returns null, the ExceptionMiddleware will render a response.
        return null;
    }
]);