Skip to content
Myr

fix(compose): allow notFound handler to be async (#1729)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Russell Schick · committed by GitHub · parent 0a2b54a · Browse files · 3 files+16 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+16 added−3 removed

  • tests:+14 added−1 removed
  • other:+2 added−2 removed

3 files+16 added−3 removed

modified:deno_dist/compose.ts+1 added-1 removed
modified:src/compose.test.ts+14 added-1 removed
147 unmodified lines
148describe('compose with Context - 404 not found', () => {149 const middleware: MiddlewareTuple[] = []150151 const req = new HonoRequest(new Request('http://localhost/'))152 const c: Context = new Context(req)152 const onNotFound = (c: Context) => {153 return c.text('onNotFound', 404)154 }155 const onNotFoundAsync = async (c: Context) => {156 return c.text('onNotFoundAsync', 404)157 }158 const mHandler = async (_c: Context, next: Function) => {159 await next()160 }161162 middleware.push(buildMiddlewareTuple(mHandler))163164 it('Should return 404 Response', async () => {165 const c: Context = new Context(req)166 const composed = compose<Context>(middleware, undefined, onNotFound)167 const context = await composed(c)168 expect(context.res).not.toBeNull()169 expect(context.res.status).toBe(404)170 expect(await context.res.text()).toBe('onNotFound')171 expect(context.finalized).toBe(true)172 })173174 it('Should return 404 Response - async handler', async () => {175 const c: Context = new Context(req)176 const composed = compose<Context>(middleware, undefined, onNotFoundAsync)177 const context = await composed(c)178 expect(context.res).not.toBeNull()179 expect(context.res.status).toBe(404)180 expect(await context.res.text()).toBe('onNotFoundAsync')181 expect(context.finalized).toBe(true)182 })183})184185describe('compose with Context - 401 not authorized', () => {186 const middleware: MiddlewareTuple[] = []
538 unmodified lines
modified:src/compose.ts+1 added-1 removed