question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node env - When using HTTP error code in a response, statusText is set to null

See original GitHub issue

First 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:

  1. Setup a response with an error code:
return res(
      ctx.status(401),
      ctx.json({
        message: 'Mocked response JSON body',
      }),
);
  1. If you parse statusText to format an error message, you can see null 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, Jul 16, 2020

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.

2reactions
m0t0rcommented, Jul 16, 2020

@marcosvega91 thanks a lot for the fix!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found