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