Skip to content

Commit

Permalink
fix: include error stack in log when handling uncaught exceptions (#1417
Browse files Browse the repository at this point in the history
)

feat: include error stack in log when handling uncaught exceptions

Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
  • Loading branch information
jkieboom and kettanaito committed Oct 1, 2022
1 parent 78d155f commit 933a9d6
Show file tree
Hide file tree
Showing 2 changed files with 10 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
9 changes: 9 additions & 0 deletions test/msw-api/exception-handling.test.ts
Expand Up @@ -28,4 +28,13 @@ test('transforms uncaught exceptions into a 500 response', async () => {
'ReferenceError: nonExisting is not defined',
),
})

const errors = runtime.consoleSpy.get('error')

expect(errors).toEqual(
expect.arrayContaining([
expect.stringContaining('ReferenceError: nonExisting is not defined'),
expect.stringContaining(' at '),
]),
)
})

0 comments on commit 933a9d6

Please sign in to comment.