0 follower

Final Class Yiisoft\ErrorHandler\Middleware\ErrorCatcher

InheritanceYiisoft\ErrorHandler\Middleware\ErrorCatcher
ImplementsPsr\Http\Server\MiddlewareInterface

ErrorCatcher catches all throwables from the next middlewares and renders it with a handler that implements the ThrowableResponseFactoryInterface.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\ErrorHandler\ThrowableResponseFactoryInterface $throwableResponseFactory, \Psr\EventDispatcher\EventDispatcherInterface|null $eventDispatcher null )
$throwableResponseFactory Yiisoft\ErrorHandler\ThrowableResponseFactoryInterface
$eventDispatcher \Psr\EventDispatcher\EventDispatcherInterface|null

                public function __construct(
    private readonly ThrowableResponseFactoryInterface $throwableResponseFactory,
    private readonly ?EventDispatcherInterface $eventDispatcher = null,
) {
}

            
process() public method

public \Psr\Http\Message\ResponseInterface process ( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler )
$request \Psr\Http\Message\ServerRequestInterface
$handler \Psr\Http\Server\RequestHandlerInterface

                public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    try {
        return $handler->handle($request);
    } catch (Throwable $t) {
        try {
            $this->eventDispatcher?->dispatch(new ApplicationError($t));
        } catch (Throwable $e) {
            $t = new CompositeException($e, $t);
        }
        return $this->throwableResponseFactory->create($t, $request);
    }
}