Skip to content
Myr

fix(hono-base): custom not found with middleware like compress (#2220)

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

* fix(hono-base): custom not found with middleware like compress * denoify

authored by Yusuke Wada · committed by GitHub · parent 06cb43a · Browse files · 4 files+59 added−8 removed
This commit

State

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

Diff stats

4 files+59 added−8 removed

  • tests:+53 added−0 removed
  • other:+6 added−8 removed

4 files+59 added−8 removed

modified:deno_dist/hono-base.ts+3 added-4 removed
330 unmodified lines
331 // Do not `compose` if it has only one handler332 if (matchResult[0].length === 1) {333 let res: ReturnType<H>334 try {335 res = matchResult[0][0][0][0](c, async () => {})336 if (!res) {337 return this.notFoundHandler(c)338 }335 res = matchResult[0][0][0][0](c, async () => {336 c.res = await this.notFoundHandler(c)337 })338 } catch (err) {339 return this.handleError(err, c)340 }341
82 unmodified lines
modified:src/middleware/compress/index.test.ts+33 added
modified:src/hono-base.ts+3 added-4 removed
330 unmodified lines
331 // Do not `compose` if it has only one handler332 if (matchResult[0].length === 1) {333 let res: ReturnType<H>334 try {335 res = matchResult[0][0][0][0](c, async () => {})336 if (!res) {337 return this.notFoundHandler(c)338 }335 res = matchResult[0][0][0][0](c, async () => {336 c.res = await this.notFoundHandler(c)337 })338 } catch (err) {339 return this.handleError(err, c)340 }341
82 unmodified lines
modified:src/hono.test.ts+20 added
1256 unmodified lines
1257 expect(res.status).toBe(404)1258 expect(await res.text()).toBe('404 Not Found')1259 })1260 })12611262 describe('Custom 404 Not Found with a middleware like Compress Middleware', () => {1263 const app = new Hono()12641265 // Custom Middleware which creates a new Response object after `next()`.1266 app.use('*', async (c, next) => {1267 await next()1268 c.res = new Response(await c.res.text(), c.res)1269 })12701271 app.notFound((c) => {1272 return c.text('Custom NotFound', 404)1273 })12741275 it('Custom 404 Not Found', async () => {1276 const res = await app.request('http://localhost/')1277 expect(res.status).toBe(404)1278 expect(await res.text()).toBe('Custom NotFound')1279 })1280 })1281})12821283describe('Redirect', () => {1284 const app = new Hono()
2103 unmodified lines