Skip to content
Myr

fix(hono-base): return 404 if lacking response in a single sync handler (#2909)

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

authored by Yusuke Wada · committed by GitHub · parent 0d851b6 · Browse files · 2 files+18 added−1 removed
This commit

State

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

Diff stats

2 files+18 added−1 removed

  • tests:+17 added−0 removed
  • other:+1 added−1 removed

2 files+18 added−1 removed

modified:src/hono-base.ts+1 added-1 removed
439 unmodified lines
440 (resolved: Response | undefined) =>441 resolved || (c.finalized ? c.res : this.notFoundHandler(c))442 )443 .catch((err: Error) => this.handleError(err, c))444 : res444 : res ?? this.notFoundHandler(c)445 }446447 const composed = compose<Context>(matchResult[0], this.errorHandler, this.notFoundHandler)448
82 unmodified lines
modified:src/hono.test.ts+17 added
2180 unmodified lines
2181 })2182 })2183})21842185describe('Lack returning response with a single handler', () => {2186 const app = new Hono()2187 // @ts-expect-error it should return Response to type it2188 app.get('/sync', () => {})2189 app.get('/async', async () => {})21902191 it('Should return 404 response if lacking returning response', async () => {2192 const res = await app.request('/sync')2193 expect(res.status).toBe(404)2194 })21952196 it('Should return 404 response if lacking returning response in an async handler', async () => {2197 const res = await app.request('/async')2198 expect(res.status).toBe(404)2199 })2200})22012202describe('Context is not finalized', () => {2203 it('should throw error - lack `await next()`', async () => {2204 const app = new Hono()2205 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1318 unmodified lines