{"record":{"id":"1ddd990fa444be3f","repo":"yikart/AiToEarn","slug":"task-not-found","errorCode":null,"errorMessage":"Task not found","messagePattern":"Task not found","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"project/aitoearn-electron/server/src/modules/task/adminTask.service.ts","lineNumber":84,"sourceCode":"    if (keyword) filter.title = new RegExp(keyword, 'i');\n    if (status !== undefined) filter.status = status;\n\n    return paginateModel(\n      this.taskModel,\n      {\n        page,\n        pageSize,\n      },\n      filter,\n      undefined,\n      { _id: -1 },\n    );\n  }\n\n  async findOne(id: string): Promise<Task> {\n    const task = await this.taskModel.findById(id).exec();\n    if (!task) {\n      throw new NotFoundException('Task not found');\n    }\n    return task;\n  }\n\n  async update(id: string, data: UpdateTaskDto): Promise<Task> {\n    const updatedTask = await this.taskModel.findByIdAndUpdate(id, data).exec();\n    if (!updatedTask) throw new NotFoundException('Task not found');\n    return updatedTask;\n  }\n\n  /**\n   * 更新任务状态\n   * @param task\n   * @param status\n   * @returns\n   */\n  async updateStatus(task: Task, status: TaskStatus): Promise<Task> {\n    if (status === TaskStatus.ACTIVE && task.type === TaskType.ARTICLE) {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-electron/server/src/modules/task/adminTask.service.ts#L66-L102","documentation":"NestJS HttpException (404) thrown by AdminTaskService.findOne when Mongoose findById returns no Task document. It is the canonical lookup helper, so any caller resolving a task by id surfaces this error when the id does not exist.","triggerScenarios":"Any admin task endpoint that resolves a task by path :id where the id is nonexistent, deleted, or malformed (invalid ObjectId yields null from findById).","commonSituations":"Task deleted by another admin while a client still holds its id; id copied from the wrong environment; client sending a truncated or non-ObjectId string.","solutions":["Confirm the task id exists (query the tasks collection or admin list endpoint).","Validate the id is a 24-hex-char Mongo ObjectId before calling the API.","Refresh the client's task list after deletions so stale ids are not reused."],"exampleFix":"// caller-side before\nconst task = await taskService.findOne(id);\n// after\nimport { isValidObjectId } from 'mongoose';\nif (!isValidObjectId(id)) throw new BadRequestException('Invalid task id');\nconst task = await taskService.findOne(id);","handlingStrategy":"try-catch","validationCode":"import { isValidObjectId } from 'mongoose';\nif (!isValidObjectId(id)) throw new BadRequestException('Invalid task id');","typeGuard":"function isTask(t: Task | null | undefined): t is Task {\n  return !!t && typeof t._id === 'string';\n}","tryCatchPattern":"try {\n  const task = await api.getTask(id);\n} catch (e) {\n  if (e.response?.status === 404) {\n    return { task: null, reason: 'not-found' };\n  }\n  throw e;\n}","preventionTips":["Validate ObjectId format before any task lookup.","Treat 404 as 'refresh list' signal in admin UIs.","Log the id and environment on every 404 to catch cross-env mistakes."],"tags":["rest","not-found","mongoose","nestjs"],"backgroundTag":"resource-not-found","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}