fix: handle ServerException
This commit is contained in:
parent
161f8b5bf9
commit
8ef4810ac7
|
@ -12,6 +12,7 @@ use Illuminate\Http\Response;
|
|||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use Symfony\Component\HttpFoundation\Response as ResponseAlias;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Throwable;
|
||||
|
||||
|
@ -70,7 +71,7 @@ class Handler extends ExceptionHandler
|
|||
$model = strtolower(class_basename($exception->getModel()));
|
||||
|
||||
return $this->errorResponse(trans('errors.model_not_found',['model'=>$model]),
|
||||
Response::HTTP_NOT_FOUND);
|
||||
ResponseAlias::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
if($exception instanceof AuthorizationException)
|
||||
|
@ -82,7 +83,7 @@ class Handler extends ExceptionHandler
|
|||
{
|
||||
$errors = $exception->validator->errors()->getMessages();
|
||||
|
||||
return $this->errorResponse($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
return $this->errorResponse($errors, ResponseAlias::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if ( $exception instanceof ClientException)
|
||||
|
@ -99,20 +100,20 @@ class Handler extends ExceptionHandler
|
|||
|
||||
if($exception instanceof AuthenticationException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED);
|
||||
return $this->errorResponse($exception->getMessage(), ResponseAlias::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if ($exception instanceof OAuthServerException)
|
||||
{
|
||||
return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
return $this->errorResponse($exception->getMessage(), ResponseAlias::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if ($exception instanceof ServerException)
|
||||
{
|
||||
$errorBody = $exception->getResponse()->getBody()->getContents();
|
||||
$error = json_decode($errorBody);
|
||||
$message = $error ? $error->error : $exception->getMessage();
|
||||
$code = $error ? $error->status : Response::HTTP_INTERNAL_SERVER_ERROR;
|
||||
$message = $error?->error ?? $exception->getMessage();
|
||||
$code = $error?->status ?? ResponseAlias::HTTP_INTERNAL_SERVER_ERROR;
|
||||
return $this->errorResponse($message,$code);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue