Regression in v4: expect(404) treats status code 404 as an error
See original GitHub issueConsider 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:
- Created 5 years ago
- Reactions:6
- Comments:9 (4 by maintainers)
Top 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 >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
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.
Closing as fixed by #1468