fix(koa): Only set error code for Feathers errors (#2793)

This commit is contained in:
David Luecke 2022-10-12 10:18:07 -07:00 committed by GitHub
parent 474a9fda21
commit d3ee41e27b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -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()

View File

@ -199,6 +199,7 @@ describe('@feathersjs/koa', () => {
let called = false
const server = await app.listen(8787)
server.on('close', () => {
called = true
})