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.

Regression in v4: expect(404) treats status code 404 as an error

See original GitHub issue

Consider the following code snippet:

const supertest = require('supertest');

supertest('http://example.com')
  .get('/path-not-found')
  .expect(404)
  .then(
    ok => console.log('PASS'),
    err => {
      console.error('FAIL', err.stack);
      process.exit(1);
    });

Run it using supertest@3.4.2 to get the expected outcome:

PASS

Run it using supertest@4.0.0 to reproduce the bug:

FAIL Error: Not Found
    at Test.Request.callback (/private/tmp/bug/node_modules/supertest/node_modules/superagent/lib/node/index.js:804:15)
    at IncomingMessage.parser (/private/tmp/bug/node_modules/supertest/node_modules/superagent/lib/node/index.js:1036:18)
    at Stream.emit (events.js:182:13)
    at Unzip.unzip.on (/private/tmp/bug/node_modules/supertest/node_modules/superagent/lib/node/unzip.js:55:12)
    at Unzip.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
holmcommented, Mar 12, 2019

This was definitely surprising to us. It seems to be listed as a “minor change” int he history, but its not easy to understand what “all error events” mean.

I think this will be very surprising to most users, since there is a very big difference between catching an error and checking for a status.

0reactions
bajtoscommented, Mar 18, 2019

Closing as fixed by #1468

Read more comments on GitHub >

github_iconTop Results From Across the Web

expect(404) treats status code 404 as an error · Issue #1466 ...
I have reviewed the changes in supertest and superagent, but not was able to find the source of the problem. supertest changes from...
Read more >
404 vs. Soft 404 Errors: What's The Difference & How To Fix ...
“The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource or is...
Read more >
Is it correct to return 404 when a REST resource is not found?
The HTTP 404 Not Found client error response code indicates that the server can't find the requested resource. Links which lead to a...
Read more >
Appendix 1 to Subpart P of Part 404—Listing of Impairments
When the residual impairment(s) involves another body system, we will evaluate the impairment(s) under the listings in the relevant body system( ...
Read more >
Should APIs use 404 as an error code? - Medium
This means that API designers need error codes that clearly distinguish between “You requested a record that does not exist” and “You called...
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