public function __invoke($error, Request $request, Response $response, callable $out = null)
{
$status = 500;
$errorCode = $error->getCode();
// If it seems to be a valid HTTP status code, we pass on the
// exception's status.
if (is_int($errorCode) && $errorCode >= 400 && $errorCode < 600) {
$status = $errorCode;
}
if ($this->debug && !in_array($errorCode, [403, 404])) {
$whoops = new WhoopsMiddleware();
return $whoops($error, $request, $response, $out);
}
// Log the exception (with trace)
$this->logger->debug($error);
$errorPage = $this->getErrorPage($status);
return new HtmlResponse($errorPage, $status);
}