From d3ee41e27b0ea5d29b344d6584ab03e48d16e2b4 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Wed, 12 Oct 2022 10:18:07 -0700 Subject: [PATCH] fix(koa): Only set error code for Feathers errors (#2793) --- packages/koa/src/handlers.ts | 4 ++-- packages/koa/test/index.test.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) 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 })