Skip to content
Myr

fix(compose): fix it for error handling with `async` (#583)

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 03c3dec · Browse files · 3 files+53 added−12 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+53 added−12 removed

  • tests:+23 added−0 removed
  • other:+30 added−12 removed

3 files+53 added−12 removed

modified:deno_dist/compose.ts+15 added-6 removed
modified:src/compose.ts+15 added-6 removed
modified:src/hono.test.ts+23 added
568 unmodified lines
569 c.res = c.text(`Handle the error in middleware, original message is ${message}`, 500)570 }571 })572573 app.get('/handle-error-in-middleware-async', async (c, next) => {574 await next()575 if (c.error) {576 const message = c.error.message577 c.res = c.text(578 `Handle the error in middleware with async, original message is ${message}`,579 500580 )581 }582 })583584 app.get('/handle-error-in-middleware', () => {585 throw new Error('Error message')586 })587588 app.get('/handle-error-in-middleware-async', async () => {589 throw new Error('Error message')590 })591592 it('Should handle the error in middleware', async () => {593 const res = await app.request('https://example.com/handle-error-in-middleware')594 expect(res.status).toBe(500)595 expect(await res.text()).toBe(596 'Handle the error in middleware, original message is Error message'597 )598 })599600 it('Should handle the error in middleware - async', async () => {601 const res = await app.request('https://example.com/handle-error-in-middleware-async')602 expect(res.status).toBe(500)603 expect(await res.text()).toBe(604 'Handle the error in middleware with async, original message is Error message'605 )606 })607})608609describe('Request methods with custom middleware', () => {610 const app = new Hono()
529 unmodified lines