app/Exceptions/Handler.php
/**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \Throwable
     */
Render an exception into an HTTP response.

@throws \Throwable
Render an exception into an HTTP response . @throws \ Throwable
public function render($request, Throwable $exception)
    {
        if(Str::lower($request->segment(1)) === 'api'){
            if ($exception instanceof ValidationException) {
                return $this->fail($exception->validator->errors()->first());
            } elseif ($exception instanceof ModelNotFoundException) {
                return $this->fail("一不小心数据走丢了～～～",10003,[],200);
            } else if ($exception instanceof NotFoundHttpException) {
                return $this->fail('路由未找到',10004,[],$exception->getStatusCode());
            } else if ($exception instanceof MethodNotAllowedHttpException) {
                return $this->fail('请求方法不存在',10005,[]);
            } else if ($exception instanceof UnauthorizedHttpException) { 
                return $this->fail('无效的访问令牌',10006,null,401);
            } elseif ($exception instanceof AuthenticationException) { 
                return $this->fail('无效的访问令牌',10006,null,401);
            } elseif ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException &&
                $exception->getStatusCode() == 403){
                return $this->fail('没有访问权限，请联系管理员',10007,null,$exception->getStatusCode());
            }
        }
        return parent::render($request, $exception);
    }
public function render ( $ request , Throwable $ exception ) { if ( Str :: lower ( $ request -> segment ( 1 ) ) === 'api' ) { if ( $ exception instanceof ValidationException ) { return $ this -> fail ( $ exception -> validator -> errors ( ) -> first ( ) ) ; } elseif ( $ exception instanceof ModelNotFoundException ) { return $ this -> fail ( " 一不小心数据走丢了～～～",10003,[],200); } else if ( $ exception instanceof NotFoundHttpException ) { return $ this -> fail ( '路由未找到',10004,[], $ excep t i o n - >getStatu sC ode()); } else if ( $ exception instanceof MethodNotAllowedHttpException ) { return $ this -> fail ( '请求方法不存在',10005,[]); } else if ( $ exception instanceof UnauthorizedHttpException ) { return $ this -> fail ( '无效的访问令牌',10006,null,40 1 ); } elseif ( $ exception instanceof AuthenticationException ) { return $ this -> fail ( '无效的访问令牌',10006,null,40 1 ); } elseif ( $ exception instanceof \ Symfony \ Component \ HttpKernel \ Exception \ HttpException && $ exception -> getStatusCode ( ) == 403 ) { return $ this -> fail ( '没有访问权限，请联系管理员',10007,null,$exception->ge t Statu s Code ( ) ); } } return parent :: render ( $ request , $ exception ) ; }
Render an exception into an HTTP response.
Render an exception into an HTTP response .
//这个在jwt.auth 中间件中抛出 //这个异常在 auth:api 中间件中抛出 // return $this->fail($exception->getMessage().' '.$exception->getFile(). ' '.$exception->getLine(),10001,null); //        return parent::render($request, $exception);