From f31f02d4cc0739c4c778a77f786d769634c32e10 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/src/Http/Middleware/HandleErrorsWithWhoops.php b/src/Http/Middleware/HandleErrorsWithWhoops.php index 83df56af9..317d3dd2d 100644 --- a/src/Http/Middleware/HandleErrorsWithWhoops.php +++ b/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); } } }