diff --git a/src/setupWorker/start/createRequestListener.ts b/src/setupWorker/start/createRequestListener.ts index 0c9a9d229..4b62fe891 100644 --- a/src/setupWorker/start/createRequestListener.ts +++ b/src/setupWorker/start/createRequestListener.ts @@ -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, diff --git a/test/msw-api/exception-handling.test.ts b/test/msw-api/exception-handling.test.ts index d63328cc1..1432b67c4 100644 --- a/test/msw-api/exception-handling.test.ts +++ b/test/msw-api/exception-handling.test.ts @@ -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') })