yikart/AiToEarn · error · Error
Failed to fetch user info
Error message
Failed to fetch user info
What it means
getUserInfo calls Google's userinfo endpoint with the user's access token and returns response.data. Any failure — 401 invalid/expired token, network error, malformed response — is caught and rethrown as Error('Failed to fetch user info'), so the caller only sees the generic message while the real cause is only visible in the console.error log.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/google/google.service.ts:822
}
/**
* 获取已授权的用户信息
* @param data
*/
async getUserInfo(accessToken: string, token) {
try {
const response = await axios.get('https://www.googleapis.com/oauth2/v3/userinfo', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
// 返回用户信息
return response.data;
} catch (err) {
console.error('Error fetching user info:', err);
throw new Error('Failed to fetch user info');
}
}
}
View on GitHub (pinned to d3aa8bea5b)
Solutions
- Refresh the access token (refreshAccessToken) before calling getUserInfo if it may be expired
- Confirm the OAuth consent request included openid, email and profile scopes
- Check console.error output for the underlying HTTP status and Google error body
- If the token is invalid_grant/revoked, require the user to reconnect the Google account
- Return a structured 401/502 from the controller instead of the raw generic Error
Defensive patterns
Strategy: try-catch
Validate before calling
if (!accessToken || typeof accessToken !== 'string') {
throw new UnauthorizedException('Missing Google access token');
} Try / catch
try {
return await googleService.getUserInfo(accessToken);
} catch (err) {
const refreshed = await refreshAccessToken(account); // token likely expired
return await googleService.getUserInfo(refreshed.access_token);
} Prevention
- Attempt a token refresh on 401 before surfacing the error
- Request openid/email/profile scopes at consent time
- Treat 401 as expired token, 403 as missing scope
- Cache userinfo briefly to reduce API calls
When it happens
Trigger: Calling getUserInfo with an access token that is expired, revoked, or missing required scopes (openid/email/profile), or when the HTTP request to the Google userinfo endpoint fails.
Common situations: Token expired between issuance and this call; scope not requested at consent time so userinfo returns 403/401; Google service outage; server egress blocked.
Related errors
- Failed to get user permissions
- Invalid Google token
- Google login failed: ${error.message}
- Failed to refresh access token
- 无法生成授权URL
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/20169cffe7f9d34f.
Report an issue: GitHub.