Final Class Yiisoft\ErrorHandler\Middleware\ErrorCatcher
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Psr\ |
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\ |
|
| process() | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $throwableResponseFactory | Yiisoft\ |
|
| $eventDispatcher | ?\ |
|
public function __construct(
private readonly ThrowableResponseFactoryInterface $throwableResponseFactory,
private readonly ?EventDispatcherInterface $eventDispatcher = null,
) {}
| public \ | ||
| $request | \ |
|
| $handler | \ |
|
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);
}
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.