Handle 500 errors in production properly

This commit is contained in:
DariusIII
2017-08-10 13:29:40 +02:00
parent 9ee4f3b8fe
commit 66f1e54971
2 changed files with 15 additions and 1 deletions
+14 -1
View File
@@ -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);
}
/**