errors()); } if ($e instanceof AuthenticationException) { return ApiResponse::error('Unauthenticated.', 401); } if ($e instanceof AuthorizationException) { return ApiResponse::error('Forbidden.', 403); } if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException || str_contains($e::class, 'NotFound')) { return ApiResponse::error('Resource not found.', 404); } if (str_contains($e::class, 'Conflict') || str_contains($e::class, 'Duplicate')) { return ApiResponse::error('Conflict.', 409); } if (str_contains($e::class, 'Unauthorized')) { return ApiResponse::error('Forbidden.', 403); } if (str_contains($e::class, 'Exception')) { report($e); } return ApiResponse::error('Server error.', 500); } }