-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
make mocking network errors work for intercepted axios requests #355
Comments
Hey, @s-pic. Thanks for the feedback and for reaching out! Please, could you create a reproduction repo for this? Ideally, with a failed state and an expected state (may be without MSW for now). We'd be happy to help you with this. |
Hey @kettanaito thanks for looking into this. I used the examples repo, and in there the rest-react example to reproduce the case in a simplified manner: https://github.com/s-pic/examples. Here are some instructions to set up and inspect my changes:
I figured I should maybe provide some more background: |
Hey there, has the provided information been sufficient? Please let me know if I can help to clarify the problem. |
Hey, @s-pic. Thanks for providing those clarifications, they are tremendously useful. I'll look into them once I have a minute. Thank you for the patience. |
Technical insightsThe issue happens because the mocked network error is handled differently in a browser and NodeJS. In a browser it's being caught and handled as a special message type sent to the Service Worker: msw/src/utils/handleRequestWith.ts Lines 115 to 126 in c254c99
In NodeJS, however, there is no such handling, as any thrown exception is handled on the Here's how an exception is handled in NRI: I'm investigating a few possibilities whether this can be changed. Will keep you updated. |
It seems that the order of emitted events in - abort
- error
+ error
+ abort Once ordered as |
The fix is published in |
This is great @kettanaito ! |
Even if I pin down the transitive dependency of Am I missing something here? @kettanaito You wrote
I figured that would just include updating the dependency to |
This issue was resolved in |
Yip, that fixed it 😅 |
Is your feature request related to a problem? Please describe.
I am currently building a httpClient for a browser-based app. I am using msw (it is awesome!) to cover edge-cases like network failures with tests on network level. The client basically wraps axios.
I was looking forward to
response.networkError()
that was added in #253 because I needed a way to simulate a network problem (like being offline).I am using
networkError(someCustomMessage)
in the response resolver. I am asserting that the error caught by axios states my custom message. Instead I am seeing the following errorMy error handling logic goes on and treats the error as timeout error, which was not my intention.
Describe the solution you'd like
I would like to augment the simulation of network errors in a way that axios treats the error as network error (
error.message === 'Network Error'
, see axios/axios#383).I would therefore like to add respective tests to https://github.com/mswjs/msw/tree/master/test/msw-api/res.
Additional context
The text was updated successfully, but these errors were encountered: