Node env - When using HTTP error code in a response, statusText is set to null
See original GitHub issueFirst of all, thanks a lot for MSW, it’s really cool 👍
Describe the bug
When using HTTP error code in a response, statusText is set to null
. It’s in node environment.
Environment
msw: 0.19.5
nodejs: 12.18.0
npm: 6.14.5
Please also provide your browser version.
To Reproduce
Steps to reproduce the behavior:
- Setup a response with an error code:
return res(
ctx.status(401),
ctx.json({
message: 'Mocked response JSON body',
}),
);
- If you parse
statusText
to format an error message, you can seenull
value:
{
"statusCode": 401,
"message": "null: Mocked response JSON body"
}
Note, same happens if you provide custom statusText
like so ctx.status(401, 'Test')
Expected behavior
Response should contain correct default statusText. Also it should be replaced by a custom one, if provided:
{
"statusCode": 401,
"message": "Unauthorized: Mocked response JSON body"
}
Screenshots
None
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Express.JS: how can I set response status by name rather ...
I think the reason express uses numbers for HTTP status codes is because node itself uses numbers as object keys for http.STATUS_CODES.
Read more >Response.statusText - Web APIs | MDN
A String containing the HTTP status message associated with the response. The default value is "". See HTTP response status codes for a...
Read more >How to use the node-fetch.Headers function in node-fetch | Snyk
To help you get started, we've selected a few node-fetch. ... Fetch HTTP Error Handler function handleHTTPError(response) { if (!response.ok) { var message ......
Read more >API Routes: Response Helpers - Next.js
API Routes include a set of Express.js-like methods for the response to help you creating new API endpoints. Learn how it works here....
Read more >Twilio Function Execution
If your code doesn't catch this error, it will result in an HTTP 500 response. Use built-in Twilio REST Helper to send an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The scenario has been tested and the fix has been released in
node-request-interceptor@0.3.3
(see Release notes).@marcosvega91, please, do you mind carrying over the update of the dependency in MSW? Feel free to use pull requests like this as an inspiration.
@marcosvega91 thanks a lot for the fix!