AuthenticationException

main
panliang 2024-04-20 10:45:25 +08:00
parent 7abf180f3b
commit f35a0e0e6d
1 changed files with 8 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use Throwable;
use Illuminate\Http\{Request, Response};
use Illuminate\Validation\ValidationException;
use Slowlyo\OwlAdmin\Exceptions\AdminException;
use Illuminate\Auth\AuthenticationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler
@ -49,4 +50,11 @@ class Handler extends ExceptionHandler
'errors' => $exception->errors(),
], $exception->status);
}
protected function unauthenticated($request, AuthenticationException $exception)
{
return $this->shouldReturnJson($request, $exception)
? response()->json(['code' => Response::HTTP_UNAUTHORIZED, 'message' => $exception->getMessage()], 401)
: redirect()->guest($exception->redirectTo() ?? route('login'));
}
}