justauth/JustAuth · error · AuthException

object.getJSONObject("error").getString("message")

Error message

object.getJSONObject("error").getString("message")

What it means

The second guard in AuthElemeRequest.getUserInfo(): when the response has a non-null 'error' object, JustAuth throws AuthException with error.message - the standard Eleme RPC error shape {"error":{"message":..,"type":..}}. This covers API-level rejections such as invalid token or insufficient scope returned after the RPC call completes.

Solutions

  1. Use the stored refreshToken to call refresh() and retry getUserInfo() with the new token.
  2. Prompt re-authorization when refresh also fails - the user may have removed the app.
  3. Check the error 'message' text: 'invalid token' means expiry; permission-related text means the app scope needs approval in the console.
  4. Keep HTTP logging on in staging to correlate error.message values with Eleme's error-code documentation.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return elemeRequest.getUserInfo(token);
} catch (AuthException e) {
    if (e.getErrorMsg() != null && e.getErrorMsg().contains("token")) {
        try {
            AuthResponse refreshed = elemeRequest.refresh(AuthToken.builder().refreshToken(refreshToken).build());
            return elemeRequest.getUserInfo(refreshed.getData());
        } catch (AuthException retry) {
            return redirectToReauthorize();
        }
    }
    throw e;
}

Prevention

When it happens

Trigger: getUserInfo() with an access token that Eleme has expired or revoked, or when the app lacks permission for the requested API - Eleme wraps the failure in an 'error' object and this branch surfaces its message.

Common situations: Long-lived sessions where the 30-day Eleme token lapsed without refresh; user deauthorized the app in Eleme; or the app's API quota was exceeded and Eleme returns an error object with a quota message.

Related errors


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

Appendix: source

Thrown at src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java:103

        paramsMap.put("nop", "1.0.0");
        paramsMap.put("id", requestId);
        paramsMap.put("action", action);
        paramsMap.put("token", authToken.getAccessToken());
        paramsMap.put("metas", metasHashMap);
        paramsMap.put("params", parameters);
        paramsMap.put("signature", signature);

        HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_JSON, requestId, false);
        String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader).getBody();

        JSONObject object = JSONObject.parseObject(response);

        // 校验请求
        if (object.containsKey("name")) {
            throw new AuthException(object.getString("message"));
        }
        if (object.containsKey("error") && null != object.get("error")) {
            throw new AuthException(object.getJSONObject("error").getString("message"));
        }

        JSONObject result = object.getJSONObject("result");

        return AuthUser.builder()
            .rawUserInfo(result)
            .uuid(result.getString("userId"))
            .username(result.getString("userName"))
            .nickname(result.getString("userName"))
            .gender(AuthUserGender.UNKNOWN)
            .token(authToken)
            .source(source.toString())
            .build();
    }

    @Override
    public AuthResponse<AuthToken> refresh(AuthToken oldToken) {
        Map<String, String> form = new HashMap<>(4);

View on GitHub (pinned to 694bbf1b01)