{"record":{"id":"03cac66df30c1599","repo":"iflytek/astron-agent","slug":"params-error-03cac6","errorCode":"PARAMS_ERROR","errorMessage":"PARAMS_ERROR","messagePattern":"PARAMS_ERROR","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":92,"sourceCode":"\n            // Call WeChat API to get pre-authorization code\n            preAuthCode = requestPreAuthCodeFromWechat(componentAccessToken);\n\n            // Cache pre-authorization code (short-term cache to prevent duplicate requests)\n            bucket.set(preAuthCode, PRE_AUTH_CODE_EXPIRE);\n            log.info(\"Got new pre-auth code: botId={}, appid={}\", botId, appid);\n        }\n\n        // Set pre-binding status to prevent official account from being bound to multiple bots\n        setPreBindStatus(appid, botId, uid);\n\n        return preAuthCode;\n    }\n\n    @Override\n    public String buildAuthUrl(String preAuthCode, String appid, String redirectUrl) {\n        if (!StringUtils.hasText(preAuthCode) || !StringUtils.hasText(redirectUrl)) {\n            throw new BusinessException(ResponseEnum.PARAMS_ERROR);\n        }\n\n        String authUrl = String.format(\n                \"https://mp.weixin.qq.com/cgi-bin/componentloginpage?\" +\n                        \"component_appid=%s&pre_auth_code=%s&redirect_uri=%s&auth_type=1\",\n                componentAppid, preAuthCode, redirectUrl);\n\n        log.info(\"Building WeChat authorization URL: appid={}, redirectUrl={}\", appid, redirectUrl);\n        return authUrl;\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void handleAuthorizedCallback(WechatAuthCallbackDto callbackData) {\n        log.info(\"Handling WeChat authorization success callback: authorizerAppid={}\", callbackData.getAuthorizerAppid());\n\n        String authorizerAppid = callbackData.getAuthorizerAppid();\n        if (!StringUtils.hasText(authorizerAppid)) {","sourceCodeStart":74,"sourceCodeEnd":110,"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#L74-L110","documentation":"PARAMS_ERROR is thrown by WechatThirdpartyServiceImpl.buildAuthUrl when either preAuthCode or redirectUrl is blank (StringUtils.hasText fails). The method cannot construct the WeChat component login page URL without both values.","triggerScenarios":"Calling buildAuthUrl with null or empty-string preAuthCode (e.g. upstream getPreAuthCode failed silently or cache empty) or a null/blank redirectUrl from the caller.","commonSituations":"Pre-auth code expired and cache returned empty before the check upstream; caller forgot to pass the configured redirect/callback URL; property not set so null flows through; race where preAuthCode fetch failed but error was swallowed.","solutions":["Ensure getPreAuthCode succeeded (non-blank) before calling buildAuthUrl; propagate its errors instead of passing blanks","Set/verify the configured redirectUrl (application property or request param) is non-empty at the call site","Add early validation at the controller layer to return a clear message about which parameter is missing","If preAuthCode is intermittently blank, check Redis cache and the component token pipeline feeding getPreAuthCode"],"exampleFix":"// before\nbuildAuthUrl(preAuthCode, appid, redirectUrl); // preAuthCode may be blank\n// after\nif (!StringUtils.hasText(preAuthCode)) {\n    preAuthCode = wechatThirdpartyService.getPreAuthCode();\n}\nAssert.hasText(redirectUrl, \"redirectUrl must be configured\");\nbuildAuthUrl(preAuthCode, appid, redirectUrl);","handlingStrategy":"validation","validationCode":"// guard before calling\nif (!StringUtils.hasText(preAuthCode)) {\n    preAuthCode = wechatThirdpartyService.getPreAuthCode();\n}\nif (!StringUtils.hasText(redirectUrl)) {\n    throw new IllegalArgumentException(\"redirectUrl must be configured\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String url = wechatThirdpartyService.buildAuthUrl(preAuthCode, appid, redirectUrl);\n} catch (BusinessException e) {\n    if (ResponseEnum.PARAMS_ERROR.getCode().equals(e.getCode())) {\n        // re-fetch preAuthCode and/or fix redirectUrl config, then retry once\n    }\n    throw e;\n}","preventionTips":["Fetch preAuthCode immediately before building the auth URL","Externalize redirectUrl into config with a startup validation check","Validate inputs at the controller boundary with clear field-level messages"],"tags":["java","wechat","validation","missing-parameter"],"backgroundTag":"empty-required-field","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"}