make mocking network errors work for intercepted axios requests
See original GitHub issueIs 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 https://github.com/mswjs/msw/pull/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 error
{
"message": "Request aborted",
"code": "ECONNABORTED"
"stack": "Error: Request aborted
at createError (D:\dev\kraken\core\node_modules\axios\lib\core\createError.js:16:15)
at XMLHttpRequestOverride.handleAbort [as onabort] (D:\dev\kraken\core\node_modules\axios\lib\adapters\xhr.js:73:14)
at XMLHttpRequestOverride.trigger (D:\dev\kraken\core\node_modules\node-request-interceptor\lib\XMLHttpRequest\XMLHttpRequest\createXMLHttpRequestOverride.js:100:92)
at XMLHttpRequestOverride.abort (D:\dev\kraken\core\node_modules\node-request-interceptor\lib\XMLHttpRequest\XMLHttpRequest\createXMLHttpRequestOverride.js:252:22)
at D:\dev\kraken\core\node_modules\node-request-interceptor\lib\XMLHttpRequest\XMLHttpRequest\createXMLHttpRequestOverride.js:182:27";
"//": "..more stuff I stripped from the error"
}
My 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 https://github.com/axios/axios/issues/383).
I would therefore like to add respective tests to https://github.com/mswjs/msw/tree/master/test/msw-api/res.
Additional context
- I can create a minimal reproduction repo if that helps.
- I would very much like to contribute here if that is possible.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Top GitHub Comments
Yip, that fixed it 😅 Thanks.
The fix is published in
node-request-interceptor@0.5.1
. MSW update to be issued.