Skip to content
Myr

Throw typeerror when middleware is not async function

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

authored by Yusuke Wada · committed by Yusuke Wada · parent 1b77b0f · Browse files · 2 files+25 added−0 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+25 added−0 removed

  • tests:+21 added−0 removed
  • other:+4 added−0 removed

2 files+25 added−0 removed

modified:src/hono.js+4 added
modified:src/hono.test.js+21 added
140 unmodified lines
141 expect(res.status).toBe(404)142 expect(await res.text()).toBe('Custom 404 Not Found')143 })144})145146describe('Error Handling', () => {147 const app = new Hono()148149 it('Middleware must be async function', () => {150 const t = () => {151 throw new TypeError()152 }153 expect(t).toThrow(TypeError)154155 const customNotFound = (c, next) => {156 next()157 if (c.res.status === 404) {158 c.res = new fetch.Response('Custom 404 Not Found', { status: 404 })159 }160 }161 expect(() => {162 app.use('*', customNotFound)163 }).toThrow(TypeError)164 })165})