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

  1. 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).
  2. For 42001/40014 (token expired): invalidate the cached provider_access_token and re-fetch via getAccessToken before retrying.
  3. For 48011/60011 (permission): apply for member-detail read permission on the service-provider app and re-publish.
  4. 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

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


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