Skip to content

Commit

Permalink
fix(koa): Only set error code for Feathers errors (#2793)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Oct 12, 2022
1 parent 474a9fd commit d3ee41e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/koa/src/handlers.ts
Original file line number Diff line number Diff line change
@@ -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>) => {
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/koa/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ describe('@feathersjs/koa', () => {
let called = false

const server = await app.listen(8787)

server.on('close', () => {
called = true
})
Expand Down

0 comments on commit d3ee41e

Please # to comment.