public static function getStatusCode($error, ResponseInterface $response) { if (($error instanceof Throwable || $error instanceof Exception) && ($error->getCode() >= 400 && $error->getCode() < 600)) { return $error->getCode(); } $status = $response->getStatusCode(); if (!$status || $status < 400 || $status >= 600) { $status = 500; } return $status; }
/** * Create/update the response representing the error. * * @param Throwable|Exception $e * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface */ public function __invoke($e, ServerRequestInterface $request, ResponseInterface $response) { $response = $response->withStatus(Utils::getStatusCode($e, $response)); $body = $response->getBody(); if ($this->isDevelopmentMode) { $escaper = new Escaper(); $body->write($escaper->escapeHtml((string) $e)); return $response; } $body->write($response->getReasonPhrase() ?: 'Unknown Error'); return $response; }