From 920802e5aed3670f58b39f9ef4eec80a2b783304 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 13 Nov 2018 07:47:01 +1030 Subject: [PATCH] Log errors when debug mode is on too --- .../FallbackExceptionHandler.php | 4 +--- src/Http/Middleware/HandleErrorsWithWhoops.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Api/ExceptionHandler/FallbackExceptionHandler.php b/src/Api/ExceptionHandler/FallbackExceptionHandler.php index f14ce579d..1087dbe89 100644 --- a/src/Api/ExceptionHandler/FallbackExceptionHandler.php +++ b/src/Api/ExceptionHandler/FallbackExceptionHandler.php @@ -54,9 +54,7 @@ class FallbackExceptionHandler implements ExceptionHandlerInterface $status = 500; $error = $this->constructError($e, $status); - if (! $this->debug) { - $this->logger->error($e); - } + $this->logger->error($e); return new ResponseBag($status, [$error]); } diff --git a/src/Http/Middleware/HandleErrorsWithWhoops.php b/src/Http/Middleware/HandleErrorsWithWhoops.php index 44e3f2881..83df56af9 100644 --- a/src/Http/Middleware/HandleErrorsWithWhoops.php +++ b/src/Http/Middleware/HandleErrorsWithWhoops.php @@ -16,10 +16,24 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\MiddlewareInterface as Middleware; use Psr\Http\Server\RequestHandlerInterface as Handler; +use Psr\Log\LoggerInterface; use Throwable; class HandleErrorsWithWhoops implements Middleware { + /** + * @var LoggerInterface + */ + protected $logger; + + /** + * @param LoggerInterface $logger + */ + public function __construct(LoggerInterface $logger) + { + $this->logger = $logger; + } + /** * Catch all errors that happen during further middleware execution. */ @@ -28,6 +42,10 @@ class HandleErrorsWithWhoops implements Middleware try { return $handler->handle($request); } catch (Throwable $e) { + if ($e->getCode() !== 404) { + $this->logger->error($e); + } + return WhoopsRunner::handle($e, $request); } }