show error messages in json for API calls #92
This commit is contained in:
parent
cba86adb28
commit
2ee655b9d1
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user