justauth/JustAuth · error · AuthException

object.getString("error")

Error message

object.getString("error")

What it means

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.

Source

Thrown at src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java:62

            .rawUserInfo(object)
            .uuid(object.getString("username"))
            .username(object.getString("username"))
            .remark(object.getString("description"))
            .blog(object.getString("website"))
            .gender(AuthUserGender.UNKNOWN)
            .token(authToken)
            .source(source.toString())
            .build();
    }

    /**
     * 检查响应内容是否正确
     *
     * @param object 请求响应内容
     */
    private void checkResponse(JSONObject object) {
        if (object.containsKey("error_code")) {
            throw new AuthException(object.getString("error"));
        }
    }
}

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Verify the CSDN app's client_id/client_secret and that the app is approved for production use.
  2. Make sure the redirect URI is registered under the CSDN app and each 'code' is exchanged only once.
  3. Enable HTTP request/response logging (e.g. via HttpUtils config) to capture the raw body, since the thrown message may be null.
  4. Wrap calls in try/catch on AuthException and report e.getErrorMsg() to your logs.

Example fix

// before - message may be null when 'error' key is missing
private void checkResponse(JSONObject object) {
    if (object.containsKey("error_code")) {
        throw new AuthException(object.getString("error"));
    }
}

// after - fall back to the raw body so callers always get a usable message
private void checkResponse(JSONObject object) {
    if (object.containsKey("error_code")) {
        String msg = object.getString("error");
        throw new AuthException(msg != null ? msg : object.toJSONString());
    }
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return csdnRequest.getUserInfo(token);
} catch (AuthException e) {
    // e.getErrorMsg() may be null for CSDN - always fall back to a generic message
    String userMsg = e.getErrorMsg() != null ? e.getErrorMsg() : "CSDN authorization failed";
    log.warn("CSDN error, msg={}", userMsg);
    return AuthResponse.builder().code(500).msg(userMsg).build();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14). Data as JSON: /api/errors/7445241bec66fc18. Report an issue: GitHub.