*/ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. */ public function register(): void { $this->reportable(function (Throwable $e) { // }); $this->renderable(function (\Exception $exception, Request $request) { if ($request->is('api*')) { if ($exception instanceof JWTException) { $mapExceptions = [ TokenInvalidException::class => '无效的token', TokenBlacklistedException::class => 'token 已被加入黑名单,请重新登录' ]; $msg = $mapExceptions[get_class($exception)] ?? $exception->getMessage(); return responseJsonAsUnAuthorized($msg); } // 拦截表单验证错误抛出的异常 elseif ($exception instanceof ValidationException) { return responseJsonAsBadRequest($exception->validator->errors()->first()); } return responseJsonAsServerError($exception->getMessage()); } return responseJsonAsServerError($exception->getMessage(), null); }); } }