From f4e380739d80f7095c67eb9d46e7b0746d727207 Mon Sep 17 00:00:00 2001 From: liutk <961510893@qq.com> Date: Mon, 20 May 2024 17:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86token=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exceptions/Handler.php | 5 +++++ 1 file changed, 5 insertions(+) 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); + } } } }