justauth/JustAuth · error · AuthException

object.getString("error")

Error message

object.getString("error")

What it means

First branch of AuthHuaweiRequest.checkResponse(): Huawei's account service signals token-endpoint failures with a top-level 'NSP_STATUS' code, and this code throws AuthException reading the sibling 'error' key. Caveat: NSP_STATUS responses often do not include an 'error' field, so the thrown message can be null - log the raw response when the message is empty.

Source

Thrown at src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java:180

     * 获取用户的实际性别。华为系统中,用户的性别:1表示女,0表示男
     *
     * @param object obj
     * @return AuthUserGender
     */
    private AuthUserGender getRealGender(JSONObject object) {
        int genderCodeInt = object.getIntValue("gender");
        String genderCode = genderCodeInt == 1 ? "0" : (genderCodeInt == 0) ? "1" : genderCodeInt + "";
        return AuthUserGender.getRealGender(genderCode);
    }

    /**
     * 校验响应结果
     *
     * @param object 接口返回的结果
     */
    private void checkResponse(JSONObject object) {
        if (object.containsKey("NSP_STATUS")) {
            throw new AuthException(object.getString("error"));
        }
        if (object.containsKey("error")) {
            throw new AuthException(object.getString("sub_error") + ":" + object.getString("error_description"));
        }
    }
}

View on GitHub (pinned to 694bbf1b01)

Solutions

  1. Re-copy client_id/client_secret from App Gallery Connect and confirm the app's OAuth 2.0 redirect settings include your callback.
  2. When the exception message is null, enable response logging to capture the NSP_STATUS value and map it against Huawei's error table.
  3. Ensure the authorization code from the callback is exchanged once and immediately.
  4. Verify your app's signing fingerprint is registered if the Huawei console requires it for server-side token exchange.

Example fix

// before - 'error' key may be absent when NSP_STATUS is present, yielding null
if (object.containsKey("NSP_STATUS")) {
    throw new AuthException(object.getString("error"));
}

// after - include the NSP status so the message is never empty
if (object.containsKey("NSP_STATUS")) {
    String msg = object.getString("error");
    throw new AuthException(msg != null ? msg : "NSP_STATUS " + object.getString("NSP_STATUS"));
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return huaweiRequest.getAccessToken(callback);
} catch (AuthException e) {
    // message may be null for NSP_STATUS failures - degrade gracefully
    String safe = e.getErrorMsg() != null ? e.getErrorMsg() : "Huawei token request failed (NSP_STATUS)";
    log.warn("Huawei NSP error: {}", safe);
    return AuthResponse.builder().code(500).msg(safe).build();
}

Prevention

When it happens

Trigger: getAccessToken()/refresh() with a wrong app secret, an invalid or expired authorization code, or an unregistered callback domain - Huawei answers with NSP_STATUS (e.g. NSP_STATUS 500 in the body) indicating the token request failed.

Common situations: App Gallery Connect credentials rotated; the callback URL domain not configured in the Huawei app's redirect settings; signature digest (SHA-256 fingerprint) of the calling backend not registered, so Huawei rejects the exchange.

Related errors


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