From f2920804831c5049b5761fb48320dcfd7e72ea7f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 12 Jan 2017 13:44:23 -0500 Subject: [PATCH] Should close #244 What a peculiar bug. Also modifies code to try and return the correct status code, as well as return JSON based errors on any request that Laravel thinks should have a JSON based response. --- app/Exceptions/Handler.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 2b89cacbf..fedfa1c4b 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -46,13 +46,12 @@ class Handler extends ExceptionHandler */ public function render($request, Exception $exception) { - if ($request->isXmlHttpRequest() || $request->ajax() || $request->is('remote/*')) { + if ($request->expectsJson()) { $response = response()->json([ 'error' => ($exception instanceof DisplayException) ? $exception->getMessage() : 'An unhandled error occured while attempting to process this request.', - ], 500); + ], ($this->isHttpException($exception)) ? $e->getStatusCode() : 500); - // parent::render() will log it, we are bypassing it in this case. - Log::error($exception); + parent::report($exception); } return (isset($response)) ? $response : parent::render($request, $exception);