yikart/AiToEarn · error · Error
Failed to get user permissions
Error message
Failed to get user permissions
What it means
getAccountScopes fetches the user's granted OAuth scopes plus token/user info from Google. If any of those HTTP calls fail (invalid access token, expired token, network error), the whole method is wrapped and rethrown as Error('Failed to get user permissions'). It's a generic wrapper hiding which of the underlying requests failed.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/google/google.service.ts:802
});
console.log('Token Info:', tokenInfo.data);
// 查询用户的基本信息
const userInfo = await google.oauth2('v2').userinfo.get({
auth: this.oauth2Client,
});
console.log('User Info:', userInfo.data);
// 返回用户的权限和信息
return {
tokenInfo: tokenInfo.data,
userInfo: userInfo.data,
};
} catch (error) {
console.error('Error getting user permissions:', error);
throw new Error('Failed to get user permissions');
}
}
/**
* 获取已授权的用户信息
* @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) {View on GitHub (pinned to d3aa8bea5b)
Solutions
- Ensure a fresh access token is obtained (refreshAccessToken) before calling getAccountScopes
- Check the console.error output for which request (tokenInfo vs userInfo) failed and its status
- If the access token is expired/invalid, trigger the re-auth/refresh flow for that account
- Verify outbound connectivity to googleapis.com from the server
- Catch this error upstream and return 401 so the client knows to re-authorize
Defensive patterns
Strategy: fallback
Validate before calling
if (!accessToken) {
throw new Error('Access token required before querying Google scopes');
} Type guard
function isTokenInfo(t: unknown): t is { access_token: string; expiry?: string } {
return !!t && typeof t === 'object' && 'access_token' in t;
} Try / catch
try {
return await googleService.getAccountScopes(accessToken);
} catch (err) {
logger.warn('Scope lookup failed, treating as minimal scopes', err);
return { tokenInfo: null, userInfo: null, scopes: [] }; // fallback
} Prevention
- Always refresh the access token before querying scopes
- Verify the account is connected before calling scope endpoints
- Catch and degrade gracefully — scope info is usually non-critical
- Check outbound connectivity to googleapis.com in health checks
When it happens
Trigger: Calling getAccountScopes with an access token that Google rejects (400/401 on tokeninfo or userinfo endpoints), or when the network request to Google fails entirely.
Common situations: Access token already expired and refresh flow was not run first; token revoked by user; calling before getUserAccessToken completed; offline/blocked network to googleapis.com.
Related errors
- Failed to fetch user info
- 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/858827974ca63919.
Report an issue: GitHub.