paascloud/paascloud-master · error · RuntimeException

获取用户信息失败

Error message

获取用户信息失败

What it means

QQImpl.getUserInfo parses the JSON returned by QQ's user-info endpoint into a QQUserInfo object using Jackson's ObjectMapper. If the response body is not valid QQUserInfo-shaped JSON (or openId cannot be attached), a RuntimeException with message '获取用户信息失败' is thrown, wrapping the original exception.

Solutions

  1. Log/inspect the raw `result` string to see what QQ actually returned
  2. Verify the access_token and openId are valid by calling QQ's token inspection endpoint
  3. Check the QQ互联 app configuration (appId/appSecret, callback domain)
  4. Decode the QQ error code (e.g. 100016 invalid token) and refresh/re-authenticate the user
  5. Wrap with a domain-specific exception instead of raw RuntimeException for better upstream handling

Example fix

// before
throw new RuntimeException("获取用户信息失败", e);
// after
log.error("QQ getUserInfo failed, raw result: {}", result, e);
throw new OAuth2Exception("获取用户信息失败: " + result, e);
Defensive patterns

Strategy: try-catch

Validate before calling

if (result == null || !result.trim().startsWith("{")) { throw new IllegalArgumentException("QQ响应非JSON: " + result); }

Type guard

function isQQUserInfo(o) { return o && typeof o === 'object' && 'openId' in o; }

Try / catch

try { QQUserInfo u = qqService.getUserInfo(openId); } catch (RuntimeException e) { log.error("QQ用户信息获取失败", e); response.redirect("/social/qq/error"); }

Prevention

When it happens

Trigger: QQ's graph API returned malformed, empty, or error JSON (e.g. invalid access_token, expired token) so objectMapper.readValue(result, QQUserInfo.class) throws; also any IO/network failure producing an unexpected string in `result`.

Common situations: Expired or revoked QQ access token; app id/secret mismatch so QQ returns an error payload instead of user info; network proxies returning HTML error pages; QQ API schema changes.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/20c5475749e459d2. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/social/qq/api/QQImpl.java:78

	 * Gets user info.
	 *
	 * @return the user info
	 */
	@Override
	public QQUserInfo getUserInfo() {

		String url = String.format(URL_GET_USERINFO, appId, openId);
		String result = getRestTemplate().getForObject(url, String.class);

		log.info("result={}", result);

		QQUserInfo userInfo;
		try {
			userInfo = objectMapper.readValue(result, QQUserInfo.class);
			userInfo.setOpenId(openId);
			return userInfo;
		} catch (Exception e) {
			throw new RuntimeException("获取用户信息失败", e);
		}
	}

}

View on GitHub (pinned to 781281a950)