Skip to content

Commit d3ee41e

Browse files
authored
fix(koa): Only set error code for Feathers errors (#2793)
1 parent 474a9fd commit d3ee41e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

packages/koa/src/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NotFound } from '@feathersjs/errors'
1+
import { FeathersError, NotFound } from '@feathersjs/errors'
22
import { FeathersKoaContext } from './declarations'
33

44
export const errorHandler = () => async (ctx: FeathersKoaContext, next: () => Promise<any>) => {
@@ -9,7 +9,7 @@ export const errorHandler = () => async (ctx: FeathersKoaContext, next: () => Pr
99
throw new NotFound('Not Found')
1010
}
1111
} catch (error: any) {
12-
ctx.response.status = error.code || 500
12+
ctx.response.status = error instanceof FeathersError ? error.code : 500
1313
ctx.body =
1414
typeof error.toJSON === 'function'
1515
? error.toJSON()

packages/koa/test/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ describe('@feathersjs/koa', () => {
199199
let called = false
200200

201201
const server = await app.listen(8787)
202+
202203
server.on('close', () => {
203204
called = true
204205
})

0 commit comments

Comments
 (0)