{"record":{"id":"3d5c60db243fdd6d","repo":"justauth/JustAuth","slug":"object-getjsonobject-error-response-getstring","errorCode":null,"errorMessage":"object.getJSONObject(\"error_response\").getString(\"zh_desc\")","messagePattern":"object\\.getJSONObject\\(\"error_response\"\\)\\.getString\\(\"zh_desc\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthJdRequest.java","lineNumber":131,"sourceCode":"        JSONObject object = JSONObject.parseObject(response);\n\n        this.checkResponse(object);\n\n        return AuthResponse.<AuthToken>builder()\n            .code(AuthResponseStatus.SUCCESS.getCode())\n            .data(AuthToken.builder()\n                .accessToken(object.getString(\"access_token\"))\n                .expireIn(object.getIntValue(\"expires_in\"))\n                .refreshToken(object.getString(\"refresh_token\"))\n                .scope(object.getString(\"scope\"))\n                .openId(object.getString(\"open_id\"))\n                .build())\n            .build();\n    }\n\n    private void checkResponse(JSONObject object) {\n        if (object.containsKey(\"error_response\")) {\n            throw new AuthException(object.getJSONObject(\"error_response\").getString(\"zh_desc\"));\n        }\n    }\n\n    @Override\n    public String authorize(String state) {\n        return UrlBuilder.fromBaseUrl(source.authorize())\n            .queryParam(\"app_key\", config.getClientId())\n            .queryParam(\"response_type\", \"code\")\n            .queryParam(\"redirect_uri\", config.getRedirectUri())\n            .queryParam(\"scope\", this.getScopes(\" \", true, AuthScopeUtils.getDefaultScopes(AuthJdScope.values())))\n            .queryParam(\"state\", getRealState(state))\n            .build();\n    }\n\n}\n","sourceCodeStart":113,"sourceCodeEnd":147,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java#L113-L147","documentation":"AuthJdRequest.checkResponse throws when the JD (Jingdong) open-platform response contains 'error_response', the envelope JD SDKs use for business errors. The message is the nested 'zh_desc' (Chinese description) field. It fires on both token exchange and user-info calls.","triggerScenarios":"Calling AuthJdRequest.getAccessToken or getUserInfo when JD returns {\"error_response\":{\"code\":...,\"zh_desc\":\"...\"}} — typical for invalid access token, expired code, or ISV permission not granted.","commonSituations":"Sandbox vs production endpoint confusion, app not yet published/approved on the JD open platform, access token past its 24h validity, or the 'sn' (site) parameter mismatch.","solutions":["Decode the zh_desc message (it states the exact JD error, e.g. invalid access token)","Refresh or re-acquire the access token if zh_desc mentions token expiry","Confirm the JD open-platform app status is approved and the OAuth scope is bound","Ensure config uses the correct unionId/endpoints for the JD environment you target"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n    jdRequest.getAuthResponse(callback);\n} catch (AuthException e) {\n    log.warn(\"JD error: {}\", e.getMessage()); // zh_desc from error_response\n    throw new AuthenticationServiceException(\"JD login failed\", e);\n}","preventionTips":["Track JD access token expiry (short-lived) and refresh proactively","Verify the app is approved on JD open platform before shipping login","Do not mix sandbox and production credentials in AuthConfig"],"tags":["oauth","jd","error-response","auth-exception"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}