{"record":{"id":"41242af8b14a5c4d","repo":"justauth/JustAuth","slug":"object-getstring-error-description-object-get","errorCode":null,"errorMessage":"object.getString(\"error_description\") / object.getString(\"error_msg\")","messagePattern":"object\\.getString\\(\"error_description\"\\) / object\\.getString\\(\"error_msg\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java","lineNumber":121,"sourceCode":"     * @since 1.9.3\n     */\n    @Override\n    public String authorize(String state) {\n        return UrlBuilder.fromBaseUrl(super.authorize(state))\n            .queryParam(\"display\", \"popup\")\n            .queryParam(\"scope\", this.getScopes(\" \", true, AuthScopeUtils.getDefaultScopes(AuthBaiduScope.values())))\n            .build();\n    }\n\n    /**\n     * 检查响应内容是否正确\n     *\n     * @param object 请求响应内容\n     */\n    private void checkResponse(JSONObject object) {\n        if (object.containsKey(\"error\") || object.containsKey(\"error_code\")) {\n            String msg = object.containsKey(\"error_description\") ? object.getString(\"error_description\") : object.getString(\"error_msg\");\n            throw new AuthException(msg);\n        }\n    }\n\n    private AuthToken getAuthToken(String response) {\n        JSONObject accessTokenObject = JSONObject.parseObject(response);\n        this.checkResponse(accessTokenObject);\n        return AuthToken.builder()\n            .accessToken(accessTokenObject.getString(\"access_token\"))\n            .refreshToken(accessTokenObject.getString(\"refresh_token\"))\n            .scope(accessTokenObject.getString(\"scope\"))\n            .expireIn(accessTokenObject.getIntValue(\"expires_in\"))\n            .build();\n    }\n}\n","sourceCodeStart":103,"sourceCodeEnd":136,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java#L103-L136","documentation":"JustAuth's Baidu adapter throws AuthException from checkResponse() when the Baidu OAuth API answers with an 'error' or 'error_code' key instead of the expected token/user payload. The exception message is taken from 'error_description' (falling back to 'error_msg'), i.e. the text Baidu itself returns. This signals the token or userinfo HTTP call was rejected by Baidu, not a bug in your code.","triggerScenarios":"Calling AuthBaiduRequest.getAccessToken()/refresh()/getUserInfo() with a wrong clientSecret, a reused or expired authorization code, a redirect_uri that does not match the one registered in Baidu's console, or an invalid/expired access_token when fetching user info.","commonSituations":"Copying the wrong API Key/Secret Key pair from the Baidu cloud console, reusing the 'code' query parameter after a redirect already consumed it, or testing locally with an http:// callback that differs from the registered redirect URI.","solutions":["Verify the Baidu client id (API Key) and client secret (Secret Key) in AuthConfig match the Baidu app console exactly.","Ensure the authorization code is used exactly once, immediately after the callback - re-calling login() with the same AuthCallback will fail.","Check config.redirectUri is byte-for-byte identical to the callback domain registered with Baidu.","Log the full AuthException message (Baidu's error_description) - it names the exact cause, e.g. 'invalid_grant' or 'expired token'."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    AuthResponse resp = baiduRequest.getUserInfo(token);\n} catch (AuthException e) {\n    log.warn(\"Baidu API error: {}\", e.getErrorMsg());\n    if (e.getErrorMsg() != null && e.getErrorMsg().contains(\"expired\")) {\n        return redirectToReauthorize(); // or refresh()\n    }\n    throw e;\n}","preventionTips":["Store the refresh token at login and call refresh() before the access token's expireIn window closes.","Consume the authorization code exactly once; key callback handling on the state parameter to dedupe reloads.","Keep Baidu API Key/Secret Key in config management and alert on 'invalid_client' errors so rotated credentials are caught early."],"tags":["oauth","baidu","justauth","api-error","auth-exception"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}