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..1a3b9ce9d 100644 --- a/test/msw-api/exception-handling.test.ts +++ b/test/msw-api/exception-handling.test.ts @@ -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 '), + ]), + ) })