yikart/AiToEarn · error · NotFoundException
任务不存在
Error message
任务不存在
What it means
NestJS 404 thrown in the admin verify-approve endpoint (PUT verify/approved/:id) when getUserTaskInfoById returns no user-task record. It means the submitted user-task id is unknown, not that the approval itself failed.
Source
Thrown at project/aitoearn-electron/server/src/modules/task/adminUserTask.controller.ts:65
@Get('count/approved/task')
async getCompletedTaskCount() {
return this.adminUserTaskService.getCompletedTaskCount();
}
@Get('count/approved/user')
async getCompletedUserCount() {
return this.adminUserTaskService.getCompletedUserCount();
}
// 通过
@ApiResult({ type: Boolean })
@Put('verify/approved/:id')
async verifyUserTaskApproved(
@GetToken() verifier: TokenInfo,
@Param('id') id: string,
) {
const userTask = await this.userTaskService.getUserTaskInfoById(id);
if (!userTask) throw new NotFoundException('任务不存在');
if (userTask.status !== UserTaskStatus.PENDING)
throw new AppHttpException(ErrHttpBack.user_task_err_status);
return this.adminUserTaskService.verifyUserTaskApproved(userTask, {
verifierUserId: verifier.id,
});
}
// 拒绝
@ApiResult({ type: Boolean })
@Put('verify/rejected/:id')
async verifyUserTaskRejected(
@GetToken() verifier: TokenInfo,
@Param('id') id: string,
@Body() data: RejectedTaskDto,
) {
const userTask = await this.userTaskService.getUserTaskInfoById(id);
if (!userTask) throw new NotFoundException('任务不存在');View on GitHub (pinned to d3aa8bea5b)
Solutions
- Refresh the review queue to get current user-task ids before approving.
- Confirm you are using a user-task id, not a task id.
- Validate id format before calling the endpoint.
Example fix
// before
if (!userTask) throw new NotFoundException('任务不存在');
// after
import { isValidObjectId } from 'mongoose';
if (!isValidObjectId(id)) throw new BadRequestException('Invalid user task id');
const userTask = await this.userTaskService.getUserTaskInfoById(id);
if (!userTask) throw new NotFoundException(`User task ${id} not found`); Defensive patterns
Strategy: validation
Validate before calling
if (!/^[0-9a-f]{24}$/i.test(id)) throw new Error('Invalid user task id');
const ut = await api.getUserTask(id);
if (!ut) throw new Error(`User task ${id} not found; refresh queue`); Try / catch
try {
await api.put(`/verify/approved/${id}`);
} catch (e) {
if (e.response?.status === 404) {
await refreshAuditQueue();
return;
}
throw e;
} Prevention
- Refresh the review queue before each approve action.
- Distinguish task ids from user-task ids in the UI.
- Catch 404 and reload instead of surfacing a raw error to auditors.
When it happens
Trigger: PUT verify/approved/:id with a nonexistent/deleted user-task id or a malformed ObjectId.
Common situations: Auditor clicking approve after the submission was deleted or purged; stale review queue page; id of a Task passed instead of a UserTask.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/a9d7190b66b4f9d7.
Report an issue: GitHub.