diff --git a/packages/koa/src/handlers.ts b/packages/koa/src/handlers.ts index 6a49311b96..154682bae9 100644 --- a/packages/koa/src/handlers.ts +++ b/packages/koa/src/handlers.ts @@ -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) => { @@ -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() diff --git a/packages/koa/test/index.test.ts b/packages/koa/test/index.test.ts index ec39f688c5..49452f5d8a 100644 --- a/packages/koa/test/index.test.ts +++ b/packages/koa/test/index.test.ts @@ -199,6 +199,7 @@ describe('@feathersjs/koa', () => { let called = false const server = await app.listen(8787) + server.on('close', () => { called = true })