yikart/AiToEarn · error · BadRequestException
accountId是必须的
Error message
accountId是必须的
What it means
GET /plat/twitter/auth/check verifies whether a Twitter account is authorized. It requires the accountId query parameter; when absent the controller throws BadRequestException('accountId是必须的') (HTTP 400). Note systemToken is injected but the accountId is not ownership-checked here — only its presence is validated.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/twitter/twitter.controller.ts:93
// 重定向到前端失败页面,带上错误信息
// return res.redirect(`${failureRedirectUrl}?error=${encodeURIComponent(error.message || 'Unknown error')}`);
return false
}
}
/**
* 检查用户是否已授权Twitter
*/
@Get('auth/check')
@ApiOperation({ summary: '检查用户Twitter授权状态' })
@ApiQuery({ name: 'accountId', required: true, description: 'Twitter账号ID' })
async checkAuthStatus(
@GetToken() systemToken: TokenInfo,
@Query('accountId') accountId: string
) {
if (!accountId) {
throw new BadRequestException('accountId是必须的');
}
return await this.twitterAuthService.isAuthorized(accountId);
}
/**
* 撤销Twitter授权
*/
@Post('auth/revoke')
@ApiOperation({ summary: '撤销Twitter授权' })
@ApiBody({
schema: {
type: 'object',
properties: {
accountId: { type: 'string', description: 'Twitter账号ID' }
}
}
})View on GitHub (pinned to d3aa8bea5b)
Solutions
- Always append accountId: GET /plat/twitter/auth/check?accountId=<id>
- Guard client-side: only call once the account id is loaded, e.g. if (!accountId) return;
- Trim the id — whitespace-only strings pass URL building but a truly empty value triggers the 400
- If accountId comes from a route param or store, verify the fetch happens after that store hydrates
Example fix
// before
useEffect(() => { checkAuth(accountId); }, []); // accountId may be undefined
// after
useEffect(() => { if (accountId) checkAuth(accountId); }, [accountId]); Defensive patterns
Strategy: validation
Validate before calling
if (typeof accountId !== 'string' || !accountId.trim()) {
throw new Error('accountId is required before checking auth status');
}
await api.get('/plat/twitter/auth/check', { params: { accountId } }); Type guard
function isNonEmptyString(v: unknown): v is string {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
return await api.get('/plat/twitter/auth/check', { params: { accountId } });
} catch (e) {
if (e.response?.status === 400) return false; // treat as not-authorized rather than crashing the UI
throw e;
} Prevention
- Gate the call on accountId being loaded from your account store
- Use the required:true Swagger query contract — omitting it always 400s
- Debounce checks so they don't fire with stale/empty state on mount
- Normalize ids (trim) before sending
When it happens
Trigger: Calling GET /plat/twitter/auth/check without ?accountId=... or with accountId= (empty string); client building the request dynamically with an undefined account variable that serializes to nothing.
Common situations: Frontend state not yet loaded when the check fires (account list still empty); Swagger/manual calls omitting the query; template literals like `?accountId=${undefined}` in fetch helpers dropping the param.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- userId和accountId是必须的
- tweetId, userId和accountId是必须的
- Invalid subtitle data: ${z.prettifyError(result.error)}
- Canvas not provided and no vid:// video source found in Trac
- 下载失败: ${response.status}
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/112b0f8651d3eb68.
Report an issue: GitHub.