From aa442f2cb897dd8a5817fba5e65cec69d0967ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Sun, 7 Jul 2019 08:57:40 -0400 Subject: [PATCH] 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 --- .../src/Http/Middleware/HandleErrorsWithWhoops.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Http/Middleware/HandleErrorsWithWhoops.php b/framework/core/src/Http/Middleware/HandleErrorsWithWhoops.php index 83df56af9..317d3dd2d 100644 --- a/framework/core/src/Http/Middleware/HandleErrorsWithWhoops.php +++ b/framework/core/src/Http/Middleware/HandleErrorsWithWhoops.php @@ -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); } } }