Equip\Handler\ExceptionHandler::__invoke PHP Метод

__invoke() публичный Метод

public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
Результат Psr\Http\Message\ResponseInterface
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
    {
        try {
            return $next($request, $response);
        } catch (Exception $e) {
            if ($this->logger) {
                $this->logger->error($e->getMessage(), ['exception' => $e]);
            }
            $type = $this->type($request);
            $response = $response->withHeader('Content-Type', $type);
            try {
                if (method_exists($e, 'getHttpStatus')) {
                    $code = $e->getHttpStatus();
                } else {
                    $code = $e->getCode();
                }
                $response = $response->withStatus($code);
            } catch (InvalidArgumentException $_) {
                // Exception did not contain a valid code
                $response = $response->withStatus(500);
            }
            if ($e instanceof HttpException) {
                $response = $e->withResponse($response);
            }
            $handler = $this->handler($type);
            $this->whoops->pushHandler($handler);
            $body = $this->whoops->handleException($e);
            $response->getBody()->write($body);
            $this->whoops->popHandler();
            return $response;
        }
    }