Set Whoops middleware HTTP status to error code (#1648)

* Use error code for HTTP status, defaults to 500
* Use logic from HandleErrorsWithView, make sure status is valid
This commit is contained in:
David Sevilla Martín 2019-07-07 08:57:40 -04:00 committed by Franz Liedke
parent 7e0855d9da
commit aa442f2cb8

View File

@ -42,11 +42,19 @@ class HandleErrorsWithWhoops implements Middleware
try {
return $handler->handle($request);
} catch (Throwable $e) {
if ($e->getCode() !== 404) {
$status = 500;
$errorCode = $e->getCode();
if ($errorCode !== 404) {
$this->logger->error($e);
}
return WhoopsRunner::handle($e, $request);
if (is_int($errorCode) && $errorCode >= 400 && $errorCode < 600) {
$status = $errorCode;
}
return WhoopsRunner::handle($e, $request)
->withStatus($status);
}
}
}