{"record":{"id":"21d9239ab0d6e434","repo":"iflytek/astron-agent","slug":"wechat-auth-failed","errorCode":"WECHAT_AUTH_FAILED","errorMessage":"WECHAT_AUTH_FAILED","messagePattern":"WECHAT_AUTH_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/wechat/impl/WechatThirdpartyServiceImpl.java","lineNumber":137,"sourceCode":"            return;\n        }\n\n        try {\n            // Initialize authorization token\n            initAuthorizationToken(authorizerAppid, callbackData.getAuthorizationCode());\n\n            // Establish binding relationship\n            // Note: Need to get user ID from pre-binding information, temporarily using placeholder\n            String uid = getUidFromPreBindInfo(authorizerAppid, botId);\n            botOffiaccountService.bind(botId, authorizerAppid, uid);\n\n            // Clean up cache\n            cleanupPreBindCache(authorizerAppid, botId);\n\n            log.info(\"WeChat authorization success callback handled successfully: botId={}, authorizerAppid={}\", botId, authorizerAppid);\n        } catch (Exception e) {\n            log.error(\"WeChat authorization success callback handling failed: botId={}, authorizerAppid={}\", botId, authorizerAppid, e);\n            throw new BusinessException(ResponseEnum.WECHAT_AUTH_FAILED);\n        }\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void handleUpdateAuthorizedCallback(WechatAuthCallbackDto callbackData) {\n        log.info(\"Handling WeChat authorization update callback: authorizerAppid={}\", callbackData.getAuthorizerAppid());\n\n        // Authorization update handling logic is similar to authorization success\n        handleAuthorizedCallback(callbackData);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void handleUnauthorizedCallback(WechatAuthCallbackDto callbackData) {\n        log.info(\"Handling WeChat unauthorized callback: authorizerAppid={}\", callbackData.getAuthorizerAppid());\n\n        String authorizerAppid = callbackData.getAuthorizerAppid();","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/wechat/impl/WechatThirdpartyServiceImpl.java#L119-L155","documentation":"WECHAT_AUTH_FAILED wraps any exception raised while processing the WeChat authorization-success callback in handleAuthorizedCallback. The catch-all logs the real cause and rethrows as this generic business error, so the actual failure (DB write, cache, bot lookup) is hidden behind the wrapper.","triggerScenarios":"Any exception inside handleAuthorizedCallback: bot record not found for the bound botId, database update failures persisting the authorizer appid, Redisson cache operations failing, or cleanup of the pre-bind cache throwing.","commonSituations":"Redis unavailable during pre-bind cache cleanup; bot deleted between initiating authorization and the WeChat callback arriving; DB constraint violation when saving authorization info; WeChat re-sending an old/duplicate callback.","solutions":["Read the logged cause line ('WeChat authorization success callback handling failed: botId=..., authorizerAppid=...') to find the real exception","Verify the botId from the pre-bind cache still exists and retry the authorization flow from the beginning if it was deleted","Check Redis and database health at callback time; transient outages will surface as this error","Make callback handling idempotent so duplicate WeChat callbacks don't trip constraint violations"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify bot and cache state before triggering authorization\nChatBotBase bot = chatBotBaseMapper.selectById(botId);\nif (bot == null || !StringUtils.hasText(redissonClient.getBucket(preBindKey(botId)).get())) {\n    // restart the bind flow instead of waiting for the callback\n}","typeGuard":null,"tryCatchPattern":"try {\n    wechatThirdpartyService.handleAuthorizedCallback(callbackData);\n} catch (BusinessException e) {\n    if (ResponseEnum.WECHAT_AUTH_FAILED.getCode().equals(e.getCode())) {\n        log.error(\"auth callback failed; inspect wrapped cause in logs, then retry bind flow\", e);\n        // restart authorization from getPreAuthCode/buildAuthUrl\n    }\n    throw e;\n}","preventionTips":["Read the logged root cause — this error always wraps a specific exception","Make callback handling idempotent for duplicate WeChat callbacks","Keep bot records and pre-bind cache TTLs aligned with WeChat callback latency","Monitor Redis/DB health; outages surface as this generic error"],"tags":["java","wechat","oauth-callback","wrapped-exception"],"backgroundTag":"oauth-token-exchange-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}