Skip to content

Commit e2af5aa

Browse files
committed
fix(setupWorker): simplify the handler exception error message
1 parent 56d48b7 commit e2af5aa

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

‎src/browser/sources/service-worker-source.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,10 @@ class ServiceWorkerHttpNetworkFrame extends HttpNetworkFrame {
382382
}
383383

384384
if (reason instanceof Error) {
385-
devUtils.error(
386-
`Uncaught exception in the request handler for "%s %s":
387-
388-
%s
389-
390-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
385+
devUtils.warn(
386+
`Uncaught exception in the request handler for "%s %s". This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
391387
this.data.request.method,
392388
this.data.request.url,
393-
reason.stack ?? reason,
394389
)
395390

396391
// Treat exceptions during the request handling as 500 responses.

‎test/browser/msw-api/setup-worker/scenarios/errors/internal-error.test.ts‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,39 @@ test('propagates the exception originating from a handled request', async ({
44
loadExample,
55
spyOnConsole,
66
fetch,
7-
waitFor,
87
makeUrl,
98
}) => {
109
const consoleSpy = spyOnConsole()
1110
await loadExample(new URL('./internal-error.mocks.ts', import.meta.url))
1211

1312
const endpointUrl = makeUrl('/user')
14-
const res = await fetch(endpointUrl)
13+
const response = await fetch(endpointUrl)
1514

1615
// Expect the exception to be handled as a 500 error response.
17-
expect(res.status()).toBe(500)
18-
expect(res.statusText()).toBe('Request Handler Error')
19-
expect(await res.json()).toEqual({
16+
expect.soft(response.status()).toBe(500)
17+
expect.soft(response.statusText()).toBe('Request Handler Error')
18+
await expect(response.json()).resolves.toEqual({
2019
name: 'Error',
2120
message: 'Custom error message',
2221
stack: expect.stringContaining('Error: Custom error message'),
2322
})
2423

2524
// Expect standard request failure message from the browser.
26-
await waitFor(() => {
27-
expect(consoleSpy.get('error')).toEqual(
25+
await expect
26+
.poll(() => consoleSpy.get('error'))
27+
.toEqual(
2828
expect.arrayContaining([
2929
expect.stringContaining(
3030
'Failed to load resource: the server responded with a status of 500',
3131
),
3232
]),
3333
)
34-
})
3534

36-
expect(consoleSpy.get('error')).toEqual(
35+
expect(consoleSpy.get('warning')).toEqual(
3736
expect.arrayContaining([
38-
expect.stringContaining(`\
39-
[MSW] Uncaught exception in the request handler for "GET ${endpointUrl}":
40-
41-
Error: Custom error message
42-
`),
37+
expect.stringContaining(
38+
`This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
39+
),
4340
]),
4441
)
4542
})

0 commit comments

Comments
 (0)