Skip to content
Myr

feat(parseResponse): set `DetailedError.name` (+ error tests) (#4344)

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

* chore(client): set `DetailedError.name` * chore: add tests for error responses

authored by Trung Dang · committed by GitHub · parent 82bdc4d · Browse files · 2 files+23 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+23 added−0 removed

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

2 files+23 added−0 removed

modified:src/client/fetch-result-please.ts+1 added
modified:src/client/utils.test.ts+22 added
149 unmodified lines
150 const app = new Hono()151 .get('/text', (c) => c.text('hi'))152 .get('/json', (c) => c.json({ message: 'hi' }))153 .get('/404', (c) => c.notFound())154 .get('/500', (c) => c.text('500 Internal Server Error', 500))155 .get('/raw', (c) => {156 c.header('content-type', '')157 return c.body('hello')158 })
17 unmodified lines
176 }),177 http.get('http://localhost/404', () => {178 return HttpResponse.text('404 Not Found', { status: 404 })179 }),180 http.get('http://localhost/500', () => {181 return HttpResponse.text('500 Internal Server Error', { status: 500 })182 }),183 http.get('http://localhost/raw', () => {184 return HttpResponse.text('hello', {185 headers: {186 'content-type': '',
53 unmodified lines
240 const result = await parseResponse(client.rawBuffer.$get())241 expect(result).toMatchInlineSnapshot('"hono"')242 type _verify = Expect<Equal<typeof result, string>>243 }),244 it('should throw error matching snapshots', async () => {245 // Defined 404 route246 await expect(parseResponse(client['404'].$get())).rejects.toThrowErrorMatchingInlineSnapshot(247 '[DetailedError: 404 Not Found]'248 )249250 // Defined 500 route251 await expect(parseResponse(client['500'].$get())).rejects.toThrowErrorMatchingInlineSnapshot(252 '[DetailedError: 500 Internal Server Error]'253 )254255 // Not defined route256 // Note: the error in this test case is thrown at the `fetch` call (.$get()), not during the `parseResponse` call, so I think `parseResponse` should not try to catch and wrap it into a structured error, which could be inconsistent, if the user awaited the fetch.257 await expect(258 // @ts-expect-error noRoute is not defined259 parseResponse(client['noRoute'].$get())260 ).rejects.toThrowErrorMatchingInlineSnapshot('[TypeError: fetch failed]')261 }),262 ])263})