Final Class Yiisoft\ErrorHandler\Middleware\ErrorCatcher
| Inheritance | Yiisoft\ErrorHandler\Middleware\ErrorCatcher |
|---|---|
| Implements | Psr\Http\Server\MiddlewareInterface |
ErrorCatcher catches all throwables from the next middlewares
and renders it with a handler that implements the ThrowableResponseFactoryInterface.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ErrorHandler\Middleware\ErrorCatcher | |
| process() | Yiisoft\ErrorHandler\Middleware\ErrorCatcher |
Method Details
| 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,
) {
}
| 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);
}
}
Signup or Login in order to comment.