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.
This commit is contained in:
Dane Everitt 2017-01-12 13:44:23 -05:00
parent 8323477d0c
commit f292080483
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -46,13 +46,12 @@ class Handler extends ExceptionHandler
*/ */
public function render($request, Exception $exception) public function render($request, Exception $exception)
{ {
if ($request->isXmlHttpRequest() || $request->ajax() || $request->is('remote/*')) { if ($request->expectsJson()) {
$response = response()->json([ $response = response()->json([
'error' => ($exception instanceof DisplayException) ? $exception->getMessage() : 'An unhandled error occured while attempting to process this request.', '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. parent::report($exception);
Log::error($exception);
} }
return (isset($response)) ? $response : parent::render($request, $exception); return (isset($response)) ? $response : parent::render($request, $exception);