From 66f1e54971e394353b892818d23deb3c42db122f Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 10 Aug 2017 13:29:40 +0200 Subject: [PATCH] Handle 500 errors in production properly --- Changelog | 1 + app/Exceptions/Handler.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index cbd794a83..fae0c1247 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-08-10 DariusIII + * Chg: Handle 500 errors in production properly * Chg: Further improve maintenance mode 2017-08-09 DariusIII * Chg: Add maintenance mode with custom page displayed diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index a747e31b8..0fbb7ecb2 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,6 +4,7 @@ namespace App\Exceptions; use Exception; use Illuminate\Auth\AuthenticationException; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; class Handler extends ExceptionHandler @@ -44,7 +45,19 @@ class Handler extends ExceptionHandler */ public function render($request, Exception $exception) { - return parent::render($request, $exception); + // 404 page when a model is not found + if ($exception instanceof ModelNotFoundException) { + return response()->view('errors.404', [], 404); + } + + if ($this->isHttpException($exception)) { + return $this->renderHttpException($exception); + } + // Custom error 500 view on production + if (app()->environment() === 'production') { + return response()->view('errors.503', [], 500); + } + return parent::render($request, $exception); } /**