mirror of
https://github.com/logto-io/logto.git
synced 2025-01-27 21:39:16 -05:00
refactor: use 404 when not found
This commit is contained in:
parent
6b6210feee
commit
4694c0d5ce
4 changed files with 16 additions and 6 deletions
|
@ -51,7 +51,12 @@ export const buildUpdateWhere: BuildUpdateWhere = <Schema extends SchemaLike>(
|
|||
|
||||
assert(
|
||||
!returning || entry,
|
||||
new RequestError({ code: 'entity.update_failed', name: schema.tableSingular })
|
||||
new RequestError({
|
||||
code: where.id ? 'entity.not_exists_with_id' : 'entity.not_exists',
|
||||
name: schema.tableSingular,
|
||||
id: where.id,
|
||||
status: 404,
|
||||
})
|
||||
);
|
||||
return entry;
|
||||
};
|
||||
|
|
|
@ -32,6 +32,11 @@ export const deleteApplicationById = async (id: string) => {
|
|||
where id=${id}
|
||||
`);
|
||||
if (rowCount < 1) {
|
||||
throw new RequestError({ code: 'entity.not_exists', name: Applications.tableSingular, id });
|
||||
throw new RequestError({
|
||||
code: 'entity.not_exists_with_id',
|
||||
name: Applications.tableSingular,
|
||||
id,
|
||||
status: 404,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -39,8 +39,8 @@ const errors = {
|
|||
},
|
||||
entity: {
|
||||
create_failed: 'Failed to create {{name}}.',
|
||||
update_failed: 'Failed to update {{name}}.',
|
||||
not_exists: 'The {{name}} with ID `{{id}}` does not exist.',
|
||||
not_exists: 'The {{name}} does not exist.',
|
||||
not_exists_with_id: 'The {{name}} with ID `{{id}}` does not exist.',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ const errors = {
|
|||
},
|
||||
entity: {
|
||||
create_failed: '创建 {{name}} 失败。',
|
||||
update_failed: '更新 {{name}} 失败。',
|
||||
not_exists: 'ID 为 `{{id}}` 的 {{name}} 不存在。',
|
||||
not_exists: '该 {{name}} 不存在。',
|
||||
not_exists_with_id: 'ID 为 `{{id}}` 的 {{name}} 不存在。',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue