justauth/JustAuth · error · AuthException
${errmsg}
Error message
${errmsg} What it means
AuthWeChatEnterpriseThirdQrcodeRequest.checkResponse(String) parses the raw HTTP body and throws AuthException(errmsg, source) when the JSON contains `errcode` with a non-zero value. This is the standard WeChat Work error envelope; the exception carries the provider source for context but no numeric code — only the Chinese/English errmsg string from the server.
Source
Thrown at src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseThirdQrcodeRequest.java:118
@Override
protected String doGetUserInfo(AuthToken authToken) {
JSONObject data = new JSONObject();
data.put("auth_code", authToken.getCode());
return new HttpUtils(config.getHttpConfig())
.post(userInfoUrl(authToken), data.toJSONString()).getBody();
}
@Override
protected String userInfoUrl(AuthToken authToken) {
return UrlBuilder.fromBaseUrl(source.userInfo())
.queryParam("access_token", authToken.getAccessToken()).
build();
}
private JSONObject checkResponse(String response) {
JSONObject object = JSONObject.parseObject(response);
if (object.containsKey("errcode") && object.getIntValue("errcode") != 0) {
throw new AuthException(object.getString("errmsg"), source);
}
return object;
}
}
View on GitHub (pinned to 694bbf1b01)
Solutions
- Read the errmsg and cross-reference the errcode table in WeChat Work docs (the number is in the response even though the exception only carries the text).
- For 42001/40014 (token expired): invalidate the cached provider_access_token and re-fetch via getAccessToken before retrying.
- For 48011/60011 (permission): apply for member-detail read permission on the service-provider app and re-publish.
- Log the raw response body alongside the exception to always retain the numeric errcode.
Defensive patterns
Strategy: retry
Validate before calling
// check provider token age before user-info calls
long age = System.currentTimeMillis() - providerTokenFetchedAt;
if (age > 90 * 60 * 1000L) { // refresh well before 2h expiry
providerToken = thirdQrcodeRequest.getAccessToken(dummyCallback);
} Try / catch
try {
return request.getUserInfo(token);
} catch (AuthException e) {
String m = String.valueOf(e.getMessage());
if (m.contains("access_token" ) || m.contains("42001") || m.contains("40014")) {
providerToken = fetchNewProviderToken(); // invalidate + refetch, then retry once
return request.getUserInfo(withToken(providerToken));
}
throw e;
} Prevention
- Log raw WeChat Work response bodies to retain errcode numbers.
- Apply for member-detail read permission before shipping the login flow.
- Retry once on token-expiry errors, never on permission errors.
When it happens
Trigger: WeChat Work API calls in the third-party QR flow returning errcode != 0: getuserinfo with an expired provider_access_token (40058/42001), getuserdetail without the required read permission (48011/60011), or invalid code passed from the QR callback.
Common situations: provider_access_token cached too long and expired (2h validity); the service provider app lacks '获取成员详细信息' (read-sensitive/user-detail) permission so getuserdetail fails; user belongs to a different enterprise than the authorized one; clock or encoding issues corrupting the code parameter.
Related errors
- ${errmsg}
- ${errmsg}
- 5005
- object.getString("error_description") / object.getString("er
- object.getString("msg")
AI-assisted analysis of justauth/JustAuth@694bbf1b01 (2026-08-14).
Data as JSON: /api/errors/c8196a72f69b8c0d.
Report an issue: GitHub.