dingo + jwt 搭建后 handler 全局接收异常的问题
首先,异常抛出的原因是因为 dingo接收了异常,所以需要注册到Handler:
AppServiceProvider.php
// dingo api异常注册\
app('api.exception')->register(function (\Exception $exception) {\
$request = Request::capture();\
return app('App\Exceptions\Handler')->render($request, $exception);\
});
之后就是接收异常处理了
Handler.php
if (\
($exception instanceof AuthenticationException)\
||\
($exception instanceof TokenExpiredException)\
||\
($exception instanceof TokenBlacklistedException)\
) {\
\
return response()->json([\
'code' => 401,\
'msg' => $exception->getMessage(),\
]);\
}
本作品采用《CC 协议》,转载必须注明作者和本文链接