justauth/JustAuth · error · AuthException
object.getString("sub_error") + ":" + object.getString("erro
Error message
object.getString("sub_error") + ":" + object.getString("error_description") What it means
Second branch of AuthHuaweiRequest.checkResponse(): for userinfo/token errors Huawei returns a standard OAuth2 envelope with 'error', 'sub_error' and 'error_description'; this code throws AuthException whose message concatenates sub_error + ':' + error_description (e.g. '2037:The token is expired').
Source
Thrown at src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java:183
* @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
- Split the message on ':' - the numeric left side is Huawei's sub_error code (2037/2036 = token problems) to drive refresh-vs-reauthorize logic.
- Call refresh() with the stored refresh token when sub_error indicates expiry, then retry the user-info call.
- Only request scopes that are approved in App Gallery Connect, and re-run authorization after new scopes are granted.
- Drop local sessions and re-authorize when the error indicates the grant was revoked.
Defensive patterns
Strategy: try-catch
Try / catch
try {
return huaweiRequest.getUserInfo(token);
} catch (AuthException e) {
String m = String.valueOf(e.getErrorMsg());
if (m.startsWith("2037") || m.contains("expired")) {
return huaweiRequest.refresh(AuthToken.builder().refreshToken(refreshToken).build());
}
throw e;
} Prevention
- Parse Huawei sub_error codes (the number before ':') and route 2036/2037 to refresh, others to re-authorize.
- Huawei access tokens last about 1 hour - refresh proactively in long sessions.
- Request only console-approved scopes; re-run authorization after new scopes are granted.
When it happens
Trigger: getUserInfo() or token refresh when the Huawei access token has expired or been revoked, or when the granted scopes do not cover the requested user profile - Huawei returns error plus sub_error codes.
Common situations: Huawei access tokens are short-lived (about 1 hour) and sessions that skip refresh hit the expiry; users revoking the app in Huawei ID settings; requesting profile fields (e.g. phone/email) without the corresponding scope approved.
Related errors
- object.getJSONObject("error").getString("message")
- object.getJSONObject("error").getString("message")
- object.getString("error_description")
- object.getString("message")
- object.getString("error")
AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14).
Data as JSON: /api/errors/ef4cc5dd7b461990.
Report an issue: GitHub.