{"record":{"id":"7445241bec66fc18","repo":"justauth/JustAuth","slug":"object-getstring-error","errorCode":null,"errorMessage":"object.getString(\"error\")","messagePattern":"object\\.getString\\(\"error\"\\)","errorType":"exception","errorClass":"AuthException","httpStatus":null,"severity":"error","filePath":"src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java","lineNumber":62,"sourceCode":"            .rawUserInfo(object)\n            .uuid(object.getString(\"username\"))\n            .username(object.getString(\"username\"))\n            .remark(object.getString(\"description\"))\n            .blog(object.getString(\"website\"))\n            .gender(AuthUserGender.UNKNOWN)\n            .token(authToken)\n            .source(source.toString())\n            .build();\n    }\n\n    /**\n     * 检查响应内容是否正确\n     *\n     * @param object 请求响应内容\n     */\n    private void checkResponse(JSONObject object) {\n        if (object.containsKey(\"error_code\")) {\n            throw new AuthException(object.getString(\"error\"));\n        }\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":66,"githubUrl":"https://github.com/justauth/JustAuth/blob/694bbf1b010d93404e3bfb4824d90e9ddfaebebb/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java#L44-L66","documentation":"AuthCsdnRequest.checkResponse() throws when the CSDN OpenAPI response contains an 'error_code' key; the exception message is read from the sibling 'error' field. Note the asymmetry: presence of error_code is checked, but the 'error' text may be absent in some payloads, yielding a null message - inspect the raw response when the message is unhelpful.","triggerScenarios":"getAccessToken() or getUserInfo() against CSDN when the API returns error_code - invalid app key/secret, expired authorization code, or an access token revoked by the user.","commonSituations":"CSDN open-platform app credentials changed or the app is still in review/unapproved status, so all token requests are rejected; or the callback code was consumed by an earlier request (double-click on the authorize button).","solutions":["Verify the CSDN app's client_id/client_secret and that the app is approved for production use.","Make sure the redirect URI is registered under the CSDN app and each 'code' is exchanged only once.","Enable HTTP request/response logging (e.g. via HttpUtils config) to capture the raw body, since the thrown message may be null.","Wrap calls in try/catch on AuthException and report e.getErrorMsg() to your logs."],"exampleFix":"// before - message may be null when 'error' key is missing\nprivate void checkResponse(JSONObject object) {\n    if (object.containsKey(\"error_code\")) {\n        throw new AuthException(object.getString(\"error\"));\n    }\n}\n\n// after - fall back to the raw body so callers always get a usable message\nprivate void checkResponse(JSONObject object) {\n    if (object.containsKey(\"error_code\")) {\n        String msg = object.getString(\"error\");\n        throw new AuthException(msg != null ? msg : object.toJSONString());\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return csdnRequest.getUserInfo(token);\n} catch (AuthException e) {\n    // e.getErrorMsg() may be null for CSDN - always fall back to a generic message\n    String userMsg = e.getErrorMsg() != null ? e.getErrorMsg() : \"CSDN authorization failed\";\n    log.warn(\"CSDN error, msg={}\", userMsg);\n    return AuthResponse.builder().code(500).msg(userMsg).build();\n}","preventionTips":["Never assume AuthException.getErrorMsg() is non-null - CSDN payloads can lack the 'error' text.","Enable raw response logging in non-production environments to diagnose CSDN failures.","Verify CSDN app approval status before integrating production traffic."],"tags":["oauth","csdn","justauth","api-error","null-message"],"backgroundTag":null,"analyzedSha":"694bbf1b010d93404e3bfb4824d90e9ddfaebebb","analyzedAt":"2026-08-14T15:16:59.945Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}