{"record":{"id":"251ca94f04cc0e6a","repo":"justauth/JustAuth","slug":"cause-message-251ca9","errorCode":null,"errorMessage":"${cause.message}","messagePattern":"\\$\\{cause\\.message\\}","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java","lineNumber":158,"sourceCode":"    }\n\n    @Override\n    protected void checkCode(AuthCallback authCallback) {\n        if (StringUtils.isEmpty(authCallback.getAuth_code())) {\n            throw new AuthException(AuthResponseStatus.ILLEGAL_CODE, source);\n        }\n    }\n\n    @Override\n    public AuthToken getAccessToken(AuthCallback authCallback) {\n        AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();\n        request.setGrantType(\"authorization_code\");\n        request.setCode(authCallback.getAuth_code());\n        AlipaySystemOauthTokenResponse response;\n        try {\n            response = this.alipayClient.execute(request);\n        } catch (Exception e) {\n            throw new AuthException(e);\n        }\n        if (!response.isSuccess()) {\n            throw new AuthException(response.getSubMsg());\n        }\n        return AuthToken.builder()\n            .accessToken(response.getAccessToken())\n            .uid(response.getUserId())\n            .expireIn(Integer.parseInt(response.getExpiresIn()))\n            .refreshToken(response.getRefreshToken())\n            .build();\n    }\n\n    /**\n     * 刷新access token （续期）\n     *\n     * @param authToken 登录成功后返回的Token信息\n     * @return AuthResponse\n     */","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java#L140-L176","documentation":"Generic AuthException wrapping any non-AlipayApiException thrown by alipayClient.execute while exchanging the authorization code for a token (grant_type=authorization_code). The message is the underlying cause's message; common culprits are NumberFormatException from Integer.parseInt(response.getExpiresIn()) on unexpected content, network errors, or the SDK throwing a RuntimeException.","triggerScenarios":"AuthAlipayRequest.getAccessToken where DefaultAlipayClient.execute throws an unchecked exception: malformed gateway response making getExpiresIn() non-numeric, connection reset, missing proxy. AlipayApiException is also caught here since the catch is on Exception.","commonSituations":"Alipay gateway returned an HTML error page or maintenance response so the parsed fields are garbage; proxy host/port misconfigured; alipayPublicKey wrong causing runtime errors during response verification.","solutions":["Read the wrapped cause in the AuthException — its class and message identify the real failure","If it is NumberFormatException, capture the raw response to see what the gateway actually returned (maintenance page, error JSON without expiresIn)","Verify network/proxy configuration on the DefaultAlipayClient constructor","Validate alipayPublicKey matches the app's encryption mode (public-key vs cert mode)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    AuthToken t = alipayRequest.getAccessToken(callback);\n} catch (AuthException e) {\n    Throwable c = e.getCause() != null ? e.getCause() : e;\n    if (c instanceof java.net.ConnectException || c instanceof java.net.SocketTimeoutException) {\n        // transient network — safe to retry the code exchange ONLY if it never succeeded\n        scheduleRetry();\n    } else {\n        log.error(\"alipay token exchange failed\", c); throw e;\n    }\n}","preventionTips":["Always inspect the chained cause rather than the wrapper message","Retry only on confirmed transient network errors and only if the auth_code was not consumed","Log raw gateway responses when parsing errors appear"],"tags":["alipay","oauth","cause-chaining","network"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}