mirror of
https://github.com/feathersjs/feathers.git
synced 2026-02-01 17:37:38 +00:00
fix(koa): Only set error code for Feathers errors (#2793)
This commit is contained in:
parent
474a9fda21
commit
d3ee41e27b
@ -1,4 +1,4 @@
|
||||
import { NotFound } from '@feathersjs/errors'
|
||||
import { FeathersError, NotFound } from '@feathersjs/errors'
|
||||
import { FeathersKoaContext } from './declarations'
|
||||
|
||||
export const errorHandler = () => async (ctx: FeathersKoaContext, next: () => Promise<any>) => {
|
||||
@ -9,7 +9,7 @@ export const errorHandler = () => async (ctx: FeathersKoaContext, next: () => Pr
|
||||
throw new NotFound('Not Found')
|
||||
}
|
||||
} catch (error: any) {
|
||||
ctx.response.status = error.code || 500
|
||||
ctx.response.status = error instanceof FeathersError ? error.code : 500
|
||||
ctx.body =
|
||||
typeof error.toJSON === 'function'
|
||||
? error.toJSON()
|
||||
|
||||
@ -199,6 +199,7 @@ describe('@feathersjs/koa', () => {
|
||||
let called = false
|
||||
|
||||
const server = await app.listen(8787)
|
||||
|
||||
server.on('close', () => {
|
||||
called = true
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user