yikart/AiToEarn · error · BadRequestException
tweetId, rating和accountId是必须的
Error message
tweetId, rating和accountId是必须的
What it means
Thrown by the rateTweet endpoint when the body lacks 'tweetId', 'rating', or 'accountId' (userId derives from the token). This is the required-params guard; it fires before the separate rating-value check, so any missing/empty field yields this message.
Source
Thrown at project/aitoearn-electron/server/src/modules/plat/twitter/twitter.controller.ts:368
schema: {
type: 'object',
properties: {
accountId: { type: 'string', description: '账号ID' },
tweetId: { type: 'string', description: '推文ID' },
rating: { type: 'string', description: '点赞 like、取消点赞 unlike' }
},
required: ['accountId', 'tweetId', 'rating']
}
})
async rateTweet(
@GetToken() systemToken: TokenInfo,
@Body('tweetId') tweetId: string,
@Body('accountId') accountId: string,
@Body('rating') rating: string,
) {
const userId = systemToken.id;
if (!tweetId || !userId || !accountId || ! rating) {
throw new BadRequestException('tweetId, rating和accountId是必须的');
}
const accessToken = await this.twitterAuthService.getUserAccessToken(accountId);
// 在方法开始处验证
if (!["like", "unlike"].includes(rating)) {
throw new BadRequestException('参数错误: rating必须为like或unlike');
}
// 后续处理
if (rating === "like") {
return this.twitterService.likeTweet(accessToken, userId, accountId, tweetId);
} else {
return this.twitterService.unlikeTweet(accessToken, userId, accountId, tweetId);
}
}
}
View on GitHub (pinned to d3aa8bea5b)
Solutions
- Send a JSON body with tweetId, accountId, and rating ('like' or 'unlike').
- Ensure Content-Type is application/json so the body is parsed.
- Disable the like button until tweetId and accountId are known.
- Verify the system token resolves to a userId.
Example fix
// before
await api.post('/twitter/tweet/rate', { tweetId });
// after
await api.post('/twitter/tweet/rate', { tweetId, accountId, rating: 'like' }); Defensive patterns
Strategy: validation
Validate before calling
if (!tweetId || !accountId || !rating) throw new Error('tweetId, accountId和rating是必须的');
await api.post('/twitter/tweet/rate', { tweetId, accountId, rating }); Type guard
function isRateRequest(p: unknown): p is { tweetId: string; accountId: string; rating: string } {
const o = p as any;
return typeof o?.tweetId === 'string' && o.tweetId.length > 0 &&
typeof o?.accountId === 'string' && o.accountId.length > 0 &&
typeof o?.rating === 'string' && o.rating.length > 0;
} Try / catch
try {
await api.post('/twitter/tweet/rate', { tweetId, accountId, rating });
} catch (e) {
if (e.response?.status === 400) revertOptimisticLikeState();
} Prevention
- Disable like/unlike buttons until tweetId and accountId are populated.
- Send JSON with Content-Type: application/json.
- Validate params client-side before optimistic UI updates.
- Roll back optimistic state when the API returns 400.
When it happens
Trigger: POST to rateTweet with a body missing tweetId, rating, or accountId; empty-string values; or an unauthenticated token yielding no userId.
Common situations: Like/unlike button submits before the tweet id is hydrated; optimistic UI toggles rating but forgets accountId; JSON body malformed so @Body() fields are undefined.
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和file是必须的
- tweetId, userId和accountId是必须的
- userId, accountId和query是必须的
- No response from Gemini
- HTTP ${response.status}
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/1db6c8945586f1c5.
Report an issue: GitHub.