Skip to content
Myr

fix(hono-base): copy notfound and error handlers in `#clone()` (#4139)

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

* fix(hono-base): copy notfound and error handlers in `#clone()` * remove `only`

authored by Yusuke Wada · committed by GitHub · parent be0dbd6 · Browse files · 3 files+40 added−4 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+40 added−4 removed

  • tests:+38 added−4 removed
  • other:+2 added−0 removed

3 files+40 added−4 removed

modified:src/utils/body.test.ts+12 added-4 removed
197 unmodified lines
198 data.append('file.file2', file2)199200 const req = createRequest(FORM_URL, 'POST', data)201202 expect(await parseBody(req, { all: true, dot: true })).toEqual({203 file: { file1, file2 },202 const result = await parseBody(req, { all: true, dot: true })203 expect(result).toMatchObject({204 file: {205 file1: { name: 'file1', type: 'application/octet-stream' },206 file2: { name: 'file2', type: 'application/octet-stream' },207 },208 })209 })210211 it('should parse multiple values if values are `File`', async () => {
8 unmodified lines
220 data.append('file', file2)221222 const req = createRequest(FORM_URL, 'POST', data)223220 expect(await parseBody(req, { all: true })).toEqual({221 file: [file1, file2],224 const result = await parseBody(req, { all: true })225 expect(result).toMatchObject({226 file: [227 { name: 'file1', type: 'application/octet-stream' },228 { name: 'file2', type: 'application/octet-stream' },229 ],230 })231 })232233 it('should parse multiple values if key ends with `[]`', async () => {
129 unmodified lines
modified:src/hono-base.ts+2 added
170 unmodified lines
171 const clone = new Hono<E, S, BasePath>({172 router: this.router,173 getPath: this.getPath,174 })175 clone.errorHandler = this.errorHandler176 clone.#notFoundHandler = this.#notFoundHandler177 clone.routes = this.routes178 return clone179 }180
341 unmodified lines
modified:src/hono.test.ts+26 added
3620 unmodified lines
3621 return c.text('Hello Hono!')3622 })3623 })3624})36253626describe('app.basePath() with the internal #clone()', () => {3627 const app = new Hono()3628 .notFound((c) => {3629 return c.text(`Custom not found`, 404)3630 })3631 .onError((error, c) => {3632 return c.text(`Custom error "${error.message}"`, 500)3633 })3634 .basePath('/api')3635 .get('/test', async () => {3636 throw new Error('API Test error')3637 })36383639 it('Should return the custom not found', async () => {3640 const res = await app.request('/api/not-found')3641 expect(res.status).toBe(404)3642 expect(await res.text()).toBe('Custom not found')3643 })36443645 it('Should return the custom error', async () => {3646 const res = await app.request('/api/test')3647 expect(res.status).toBe(500)3648 expect(await res.text()).toBe('Custom error "API Test error"')3649 })3650})