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:
parent
8baf8e5be6
commit
d2e6e1fd5b
2 changed files with 4 additions and 0 deletions
|
@ -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,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue