Skip to content

Commit

Permalink
feat: include error stack in log when handling uncaught exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jkieboom committed Sep 26, 2022
1 parent 1caf8df commit 15ab6a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/setupWorker/start/createRequestListener.ts
Expand Up @@ -105,7 +105,7 @@ export const createRequestListener = (
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/recipes/mocking-error-responses`,
request.method,
request.url,
error,
error.stack ?? error,
)

// Treat all other exceptions in a request handler as unintended,
Expand Down
4 changes: 4 additions & 0 deletions test/msw-api/exception-handling.test.ts
Expand Up @@ -28,4 +28,8 @@ test('transforms uncaught exceptions into a 500 response', async () => {
'ReferenceError: nonExisting is not defined',
),
})

const consoleError = runtime.consoleSpy.get('raw').get('error').join('\n')
expect(consoleError).toContain('ReferenceError: nonExisting is not defined')
expect(consoleError).toContain('at RestHandler.run')
})

0 comments on commit 15ab6a1

Please sign in to comment.