0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(errors): introduce Slonik Deletion Error (#177)

replase all deletion query RequeestError with DeletionError extends SlonikError
This commit is contained in:
simeng-li 2022-01-14 10:19:43 +08:00 committed by GitHub
parent dfaf79bc5f
commit 86c68739e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 23 deletions

View file

@ -0,0 +1,7 @@
import { SlonikError } from 'slonik';
export class DeletionError extends SlonikError {
public constructor() {
super('Resource not found.');
}
}

View file

@ -1,11 +1,12 @@
import { Application, ApplicationUpdate, Applications } from '@logto/schemas';
import { sql, SlonikError } from 'slonik';
import { sql } from 'slonik';
import { buildFindMany } from '@/database/find-many';
import { buildInsertInto } from '@/database/insert-into';
import pool from '@/database/pool';
import { buildUpdateWhere } from '@/database/update-where';
import { convertToIdentifiers, OmitAutoSetFields, getTotalRowCount } from '@/database/utils';
import { DeletionError } from '@/errors/SlonikError';
const { table, fields } = convertToIdentifiers(Applications);
@ -48,6 +49,6 @@ export const deleteApplicationById = async (id: string) => {
where id=${id}
`);
if (rowCount < 1) {
throw new SlonikError('Resource not found');
throw new DeletionError();
}
};

View file

@ -5,7 +5,7 @@ import { buildInsertInto } from '@/database/insert-into';
import pool from '@/database/pool';
import { buildUpdateWhere } from '@/database/update-where';
import { convertToIdentifiers, OmitAutoSetFields } from '@/database/utils';
import RequestError from '@/errors/RequestError';
import { DeletionError } from '@/errors/SlonikError';
const { table, fields } = convertToIdentifiers(Resources);
@ -60,11 +60,6 @@ export const deleteResourceById = async (id: string) => {
where id=${id}
`);
if (rowCount < 1) {
throw new RequestError({
code: 'entity.not_exists_with_id',
name: Resources.tableSingular,
id,
status: 404,
});
throw new DeletionError();
}
};

View file

@ -4,7 +4,7 @@ import { sql } from 'slonik';
import { buildInsertInto } from '@/database/insert-into';
import pool from '@/database/pool';
import { convertToIdentifiers } from '@/database/utils';
import RequestError from '@/errors/RequestError';
import { DeletionError } from '@/errors/SlonikError';
const { table, fields } = convertToIdentifiers(ResourceScopes);
@ -29,11 +29,6 @@ export const deleteScopeById = async (id: string) => {
where id=${id}
`);
if (rowCount < 1) {
throw new RequestError({
code: 'entity.not_exists_with_id',
name: ResourceScopes.tableSingular,
id,
status: 404,
});
throw new DeletionError();
}
};

View file

@ -5,7 +5,7 @@ import { buildInsertInto } from '@/database/insert-into';
import pool from '@/database/pool';
import { buildUpdateWhere } from '@/database/update-where';
import { convertToIdentifiers, OmitAutoSetFields } from '@/database/utils';
import RequestError from '@/errors/RequestError';
import { DeletionError } from '@/errors/SlonikError';
const { table, fields } = convertToIdentifiers(Users);
@ -56,11 +56,6 @@ export const deleteUserById = async (id: string) => {
where id=${id}
`);
if (rowCount < 1) {
throw new RequestError({
code: 'entity.not_exists_with_id',
name: Users.tableSingular,
id,
status: 404,
});
throw new DeletionError();
}
};