Error Handlers

Exceptions are catched by a set of error handlers. Error handlers are middlewares, receiving a PSR-7 request, a PSR-7 response and the exception.

If debug mode is set to true, Whoops will display the exception stack. Otherwise, an error template will be rendered with the appropriate http code.

Default error handlers

Below is the list of the default error handlers:

Gobline\Application\Middleware\ErrorHandler\NotFoundHandler

Catches

Gobline\Router\Exception\NoMatchingRouteException

Gobline\Application\Middleware\ErrorHandler\NotAuthenticatedHandler

Catches

Gobline\Auth\Exception\NotAuthenticatedException

Gobline\Application\Middleware\ErrorHandler\NotAuthorizedHandler

Catches

Gobline\Acl\Exception\NotAuthorizedException

Gobline\Application\Middleware\ErrorHandler\ErrorHandler

Catches

\Exception

Custom error handlers

You can add your own custom error handler to the application's exception handling:

<?php
use App\MyCustomException;
use 
App\MyCustomErrorHandler;
use 
Gobline\Application\Middleware\ErrorHandler\NotFoundHandler;
use 
Gobline\Application\Middleware\ErrorHandler\NotAuthenticatedHandler;
use 
Gobline\Application\Middleware\ErrorHandler\NotAuthorizedHandler;
use 
Gobline\Application\Middleware\ErrorHandler\ErrorHandler;
use 
Gobline\Router\Exception\NoMatchingRouteException;
use 
Gobline\Auth\Exception\NotAuthenticatedException;
use 
Gobline\Acl\Exception\NotAuthorizedException;

$app->getDispatcher()
    ->
setErrorHandlers([
        
NoMatchingRouteException::class => NotFoundHandler::class,
        
NotAuthenticatedException::class => NotAuthenticatedHandler::class,
        
NotAuthorizedException::class => NotAuthorizedHandler::class,
        
MyCustomException::class => MyCustomErrorHandler::class;
        \
Exception::class => ErrorHandler::class,
    ]);