diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 5a7b849..a1d85e6 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,6 +2,7 @@ namespace App\Exceptions; +use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Throwable; use Illuminate\Database\Eloquent\ModelNotFoundException; @@ -34,6 +35,10 @@ class Handler extends ExceptionHandler if ($request->ajax() || $request->wantsJson()) { return response()->json(['data'=>null,'code'=>404 , 'message' => '数据未找到,或已被删除' ], 404); } + }elseif($e instanceof AuthenticationException){ + if ($request->ajax() || $request->wantsJson()) { + return response()->json(['data'=>null,'code'=>401 , 'message' => '无效凭证,请先登录' ], 401); + } } } }