Skip to content

Commit

Permalink
fix: fix handling not found in compose.ts (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed May 6, 2022
1 parent c4cdad8 commit d399609
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ describe('compose with Context - 401 not authorized', () => {
return c.text('onError', 500)
}
const handler = (c: Context, next: Function) => {
c.text('Hello')
next()
return c.text('Hello')
}
const mHandler = async (c: Context, next: Function) => {
await next()
Expand Down
8 changes: 5 additions & 3 deletions src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export const compose = <C>(
let handler = middleware[i]
index = i
if (i === middleware.length) handler = next
if (!handler) return Promise.resolve(context)

if (onNotFound && context instanceof Context && !context.res) {
context.res = onNotFound(context)
if (!handler) {
if (context instanceof Context && !context.res) {
context.res = onNotFound(context)
}
return Promise.resolve(context)
}

return Promise.resolve(handler(context, dispatch.bind(null, i + 1)))
Expand Down

0 comments on commit d399609

Please sign in to comment.