show error messages in json for API calls #92

This commit is contained in:
Nabeel Shahzad 2017-12-30 09:03:45 -06:00
parent cba86adb28
commit 2ee655b9d1

View File

@ -50,6 +50,23 @@ class Handler extends ExceptionHandler
return redirect()->guest('login');
}
if($request->is('api/*')) {
$status = 400;
$http_code = $exception->getCode();
if ($this->isHttpException($exception)) {
$status = $exception->getStatusCode();
$http_code = $exception->getStatusCode();
}
return response()->json([
'error' => [
'code' => $exception->getCode() ,
'http_code' => $http_code,
'message' => $exception->getMessage()
]
], $status);
}
return parent::render($request, $exception);
}