use Exception;
use Illuminate\Auth\AuthenticationException;
+use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
*/
protected $dontReport = [
NotFoundException::class,
+ StoppedAuthenticationException::class,
];
/**
/**
* Render an exception when the API is in use.
*/
- protected function renderApiException(Exception $e): JsonResponse
+ protected function renderApiException(Throwable $e): JsonResponse
{
- $code = $e->getCode() === 0 ? 500 : $e->getCode();
+ $code = 500;
$headers = [];
+
if ($e instanceof HttpException) {
$code = $e->getStatusCode();
$headers = $e->getHeaders();
}
+ if ($e instanceof ModelNotFoundException) {
+ $code = 404;
+ }
+
$responseData = [
'error' => [
'message' => $e->getMessage(),
$code = $e->status;
}
+ if (method_exists($e, 'getStatus')) {
+ $code = $e->getStatus();
+ }
+
$responseData['error']['code'] = $code;
return new JsonResponse($responseData, $code, $headers);