0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(core): use correct status code for slonik errors (#3812)

This commit is contained in:
Charles Zhao 2023-05-06 10:17:25 +08:00 committed by GitHub
parent 8baf8e5be6
commit d2e6e1fd5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View file

@ -46,6 +46,7 @@ describe('koaSlonikErrorHandler middleware', () => {
await expect(koaSlonikErrorHandler()(ctx, next)).rejects.toMatchError( await expect(koaSlonikErrorHandler()(ctx, next)).rejects.toMatchError(
new RequestError({ new RequestError({
code: 'entity.create_failed', code: 'entity.create_failed',
status: 422,
name: Users.tableSingular, name: Users.tableSingular,
}) })
); );
@ -64,6 +65,7 @@ describe('koaSlonikErrorHandler middleware', () => {
await expect(koaSlonikErrorHandler()(ctx, next)).rejects.toMatchError( await expect(koaSlonikErrorHandler()(ctx, next)).rejects.toMatchError(
new RequestError({ new RequestError({
code: 'entity.not_exists', code: 'entity.not_exists',
status: 404,
name: Users.tableSingular, name: Users.tableSingular,
}) })
); );

View file

@ -38,6 +38,7 @@ export default function koaSlonikErrorHandler<StateT, ContextT>(): Middleware<St
if (error instanceof InsertionError) { if (error instanceof InsertionError) {
throw new RequestError({ throw new RequestError({
code: 'entity.create_failed', code: 'entity.create_failed',
status: 422,
// Assert generic type of the Class instance // Assert generic type of the Class instance
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
name: (error as InsertionError<SchemaLike, SchemaLike>).schema.tableSingular, name: (error as InsertionError<SchemaLike, SchemaLike>).schema.tableSingular,
@ -47,6 +48,7 @@ export default function koaSlonikErrorHandler<StateT, ContextT>(): Middleware<St
if (error instanceof UpdateError) { if (error instanceof UpdateError) {
throw new RequestError({ throw new RequestError({
code: 'entity.not_exists', code: 'entity.not_exists',
status: 404,
// Assert generic type of the Class instance // Assert generic type of the Class instance
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
name: (error as UpdateError<SchemaLike, SchemaLike>).schema.tableSingular, name: (error as UpdateError<SchemaLike, SchemaLike>).schema.tableSingular,