{"record":{"id":"fffd9fa0182ebf45","repo":"yikart/AiToEarn","slug":"error-fffd9f","errorCode":null,"errorMessage":"任务不存在","messagePattern":"任务不存在","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"project/aitoearn-electron/server/src/modules/task/task.controller.ts","lineNumber":82,"sourceCode":"\n  @Public()\n  @Get('info/:id')\n  @ApiOperation({ summary: '获取任务详情' })\n  @ApiResult({ type: Task })\n  async findOne(@Param('id') id: string) {\n    return await this.taskService.findOne(id);\n  }\n\n  @ApiOperation({ summary: '申请任务: 保持一定时间' })\n  @ApiResult({ type: Boolean })\n  @Post('apply/:id')\n  async applyForTask(\n    @Param('id') id: string,\n    @GetToken() token: TokenInfo,\n    @Body() body: ApplyTaskDto,\n  ) {\n    const task = await this.taskService.findOne(id);\n    if (!task) throw new NotFoundException('任务不存在');\n\n    if (!!body.taskMaterialId) {\n      const taskMaterial = await this.taskService.getTaskMaterialById(\n        body.taskMaterialId,\n      );\n      if (!taskMaterial) throw new NotFoundException('任务素材不存在');\n    }\n\n    const res = await this.userTaskService.userApplyTask(token.id, task, body);\n\n    if (!!body.taskMaterialId)\n      this.taskService.upTaskMaterialUsedCount(body.taskMaterialId);\n\n    return res;\n  }\n\n  @ApiOperation({ summary: '提交任务 id是用户任务ID' })\n  @ApiResult({ type: Boolean })","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/server/src/modules/task/task.controller.ts#L64-L100","documentation":"NestJS 404 thrown in the user-facing apply-for-task endpoint (task.controller.ts) when taskService.findOne(id) returns no task. The application cannot proceed because the target task does not exist.","triggerScenarios":"POST-style apply call with a task id that was unpublished/deleted, never existed, or is an invalid ObjectId.","commonSituations":"User opening an old share link to a removed task; task list cache pointing at a delisted task; app pointing at a different environment's task ids.","solutions":["Re-fetch the task list and use a current task id.","Validate the id is a valid ObjectId before applying.","Handle 404 in the client by showing 'task no longer available' instead of retrying."],"exampleFix":"// before\nconst task = await this.taskService.findOne(id);\nif (!task) throw new NotFoundException('任务不存在');\n// after\nimport { isValidObjectId } from 'mongoose';\nif (!isValidObjectId(id)) throw new BadRequestException('Invalid task id');\nconst task = await this.taskService.findOne(id);\nif (!task) throw new NotFoundException(`Task ${id} not found or unavailable`);","handlingStrategy":"try-catch","validationCode":"import { isValidObjectId } from 'mongoose';\nif (!isValidObjectId(id)) throw new Error('Invalid task id');\nconst task = await api.getTask(id);\nif (!task) throw new Error('Task unavailable');","typeGuard":"function hasTask(t: unknown): t is { id: string } {\n  return !!t && typeof t === 'object' && 'id' in t;\n}","tryCatchPattern":"try {\n  await api.applyForTask(id, body);\n} catch (e) {\n  if (e.response?.status === 404) {\n    showUserMessage('该任务已下线或不存在');\n    return;\n  }\n  throw e;\n}","preventionTips":["Fetch task ids only from live task-list endpoints, not shared links or caches.","Show a friendly 'task unavailable' state for 404 in the client.","Invalidate cached task lists after task unpublication."],"tags":["rest","not-found","mongoose","user-api"],"backgroundTag":"resource-not-found","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}