0
Fork 0
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:
Gao Sun 2021-08-27 17:13:49 +08:00
parent 6b6210feee
commit 4694c0d5ce
No known key found for this signature in database
GPG key ID: 0F0EFA2E36639F31
4 changed files with 16 additions and 6 deletions

View file

@ -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;
};

View file

@ -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,
});
}
};

View file

@ -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.',
},
};

View file

@ -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}} 不存在。',
},
};