Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fetch): do not print console error on request failures #383

Merged
merged 2 commits into from
Jun 29, 2023

Conversation

azangru
Copy link
Contributor

@azangru azangru commented Jun 14, 2023

Fixes #381

Description

Currently, when a network error is simulated in a response from msw server, as described in the docs, (`return res.networkError('Failed to connect')), an error message with a stack trace appears in the console, although the tests would pass.

Here is an example of how this would look like to the developer who is using msw:

image

An error message, despite passing tests, is distracting. This PR removes the console.error statement responsible for this output.

When checked locally, this change cleaned up the test log:

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this, @azangru. I think this is a move for the better. Will wait for the build to pass and then will merge.

@kettanaito kettanaito changed the title fix: remove console.error from the fetch interceptor fix(fetch): do not print console error on request failures Jun 29, 2023
@kettanaito
Copy link
Member

The CI reported that the browser test for fetch exceptions was still expecting the error to be printed in the console:

  1) [chromium] › modules/fetch/fetch-exception.browser.test.ts:3:5 › treats middleware exceptions as TypeError: Failed to fetch 

    Error: expect(received).toEqual(expected) // deep equality

    - Expected  - 3
    + Received  + 1

    - Array [
    -   "GET http://localhost:3001/resource net::ERR_FAILED",
    - ]
    + Array []

      38 |     },
      39 |   })
    > 40 |   expect(errors).toEqual(['GET http://localhost:3001/resource net::ERR_FAILED'])
         |                  ^
      41 | })
      42 |

I've adjusted the expectations here and pushed the changes. Rerunning the tests...

@kettanaito kettanaito merged commit 52bbac0 into mswjs:main Jun 29, 2023
@kettanaito
Copy link
Member

Welcome to the contributors, @azangru 🎉

@kettanaito
Copy link
Member

Released: v0.22.16 🎉

This has been released in v0.22.16!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not print error to the console in the interceptor
2 participants