yikart/AiToEarn · error · AppHttpException
fail
fail
Error message
fail
What it means
Generic failure AppHttpException thrown from the admin task-material update endpoint. It means the material id given in PUT /material/:id does not correspond to any stored task material record. The controller checks getTaskMaterialById first and throws ErrHttpBack.fail before any update happens.
Source
Thrown at project/aitoearn-electron/server/src/modules/task/adminTask.controller.ts:130
@Query() query: PagerDto,
) {
return this.adminTaskService.findTaskMaterialList(taskId, query);
}
// 添加任务素材列表
@Post('material')
async addTaskMaterial(@Body() body: ActionTaskMaterialDto) {
return this.adminTaskService.createTaskMaterial(body);
}
// 更新任务素材
@Put('material/:id')
async upTaskMaterial(
@Param('id') id: string,
@Body() body: ActionTaskMaterialDto,
) {
const info = await this.adminTaskService.getTaskMaterialById(id);
if (!info) throw new AppHttpException(ErrHttpBack.fail);
return this.adminTaskService.upTaskMaterial(id, body);
}
// 删除任务素材
@Delete('material/:id')
async deleteTaskMaterial(@Param('id') id: string) {
return this.adminTaskService.deleteTaskMaterial(id);
}
}
View on GitHub (pinned to d3aa8bea5b)
Solutions
- Verify the material id exists via the task material list/get endpoint before calling PUT material/:id.
- Check you are not passing a task id instead of a task-material id.
- Confirm the admin client is pointed at the same environment/database where the material was created.
- If the generic 'fail' code is unhelpful, replace it with a more specific ErrHttpBack entry for not-found materials.
Example fix
// before
const info = await this.adminTaskService.getTaskMaterialById(id);
if (!info) throw new AppHttpException(ErrHttpBack.fail);
// after
const info = await this.adminTaskService.getTaskMaterialById(id);
if (!info)
throw new NotFoundException(`Task material ${id} not found`); Defensive patterns
Strategy: validation
Validate before calling
const info = await api.getTaskMaterialById(id);
if (!info) throw new Error(`Skip update: material ${id} not found`);
await api.put(`/material/${id}`, body); Type guard
function isMaterial(m: unknown): m is { id: string } {
return !!m && typeof m === 'object' && typeof (m as any).id === 'string';
} Try / catch
try {
await api.put(`/material/${id}`, body);
} catch (e) {
if (e.response?.data?.code === 'fail') {
console.warn(`Material ${id} not found; refreshing list`);
await refreshMaterialList();
} else throw e;
} Prevention
- Always resolve material ids from a fresh list call, never from cached form state.
- Keep task ids and material ids in distinct, labeled fields to avoid mixups.
- Wrap admin mutations with a pre-check read of the entity.
When it happens
Trigger: PUT material/:id (admin task routes) with an id that is not a valid existing task-material id: already-deleted material, malformed/typo id, or an id belonging to another collection.
Common situations: Stale client caches referencing deleted materials, copy-pasting an id of the wrong entity type (task id vs material id), or testing against a different database than the one the material was created in.
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/ff01d0363a50ca18.
Report an issue: GitHub.