yikart/AiToEarn · error · NotFoundException

任务不存在或状态不正确

Error message

任务不存在或状态不正确

What it means

NestJS 404 (message '任务不存在或状态不正确') thrown when rolling back a user task whose status is not PENDING. Rollback is only allowed on pending submissions, so an already-approved/rejected record triggers this combined not-found-or-wrong-status error.

Source

Thrown at project/aitoearn-electron/server/src/modules/task/adminUserTask.controller.ts:100

    const userTask = await this.userTaskService.getUserTaskInfoById(id);
    if (!userTask) throw new NotFoundException('任务不存在');
    return this.adminUserTaskService.verifyUserTaskRejected(userTask, {
      verifierUserId: verifier.id,
      ...data,
    });
  }

  @ApiResult({ type: Boolean })
  @Put('rollback/rejected/:id')
  async rollbackUserTaskApproved(
    @GetToken() verifier: TokenInfo,
    @Param('id') id: string,
    @Body() data: RejectedTaskDto,
  ) {
    const userTask = await this.userTaskService.getUserTaskInfoById(id);
    if (!userTask) throw new NotFoundException('任务不存在');
    if (userTask.status !== UserTaskStatus.PENDING)
      throw new NotFoundException('任务不存在或状态不正确');

    return this.adminUserTaskService.rollbackUserTaskApproved(userTask, {
      verifierUserId: verifier.id,
      ...data,
    });
  }

  // 运行自动审核的任务
  @ApiResult({ type: Boolean })
  @Put('audit/auto/run/:id')
  async runUserTaskAuditAuto(@Param('id') id: string) {
    const userTaskInfo =
      await this.adminUserTaskService.getUserTaskInfoById(id);
    if (!userTaskInfo) throw new NotFoundException('任务不存在或状态不正确');

    const { status, message, retry, data } =
      await this.adminUserTaskService.autoAuditTask(id);

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Re-fetch the user task and only roll back while status is PENDING.
  2. If the task is already APPROVED and must be undone, use the dedicated rollback-of-approved flow or a manual DB operation per business rules.
  3. Serialize rollback with auto-audit so both cannot act on the same record simultaneously.

Example fix

// before
if (userTask.status !== UserTaskStatus.PENDING)
  throw new NotFoundException('任务不存在或状态不正确');
// after
if (userTask.status !== UserTaskStatus.PENDING)
  throw new AppHttpException(ErrHttpBack.user_task_err_status);
Defensive patterns

Strategy: validation

Validate before calling

const ut = await api.getUserTask(id);
if (!ut) throw new Error(`User task ${id} not found`);
if (ut.status !== 'PENDING') throw new Error(`Cannot rollback: status is ${ut.status}`);

Type guard

function canRollback(t: { status: UserTaskStatus }): boolean {
  return t.status === UserTaskStatus.PENDING;
}

Try / catch

try {
  await api.rollbackApproved(id, data);
} catch (e) {
  if (e.response?.status === 404) {
    const cur = await api.getUserTask(id);
    console.warn(`Rollback blocked; current status: ${cur?.status}`);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Rollback call where userTask.status !== PENDING — e.g. attempting rollback after approval was finalized by the auto-audit flow or another admin.

Common situations: Trying to undo an approval that was already committed; racing with runUserTaskAuditAuto which may have advanced the status; stale admin page showing outdated status.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/0e01f1c642c36c36. Report an issue: GitHub.