main
liutk 2024-06-29 19:09:49 +08:00
parent 3ec468f499
commit 048f2f4ecc
1 changed files with 3 additions and 0 deletions

View File

@ -6,6 +6,7 @@ use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable; use Throwable;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
{ {
@ -39,6 +40,8 @@ class Handler extends ExceptionHandler
if ($request->ajax() || $request->wantsJson()) { if ($request->ajax() || $request->wantsJson()) {
return response()->json(['data'=>null,'code'=>401 , 'message' => '无效凭证,请先登录' ], 401); return response()->json(['data'=>null,'code'=>401 , 'message' => '无效凭证,请先登录' ], 401);
} }
}elseif ($e instanceof NotFoundHttpException) {
return response()->json(['data'=>null,'code'=>404 , 'message' => '页面不存在' ], 404);
} }
} }
} }