On ECONNRESET, `assert()` calls undefined `res.status` which throws an error
See original GitHub issueWhen for some reason the remote server fails and the connection is reset, supertest
cannot handle the error properly which is why the following error is thrown:
|"TypeError: Cannot read property 'status' of undefined",
|" at Test.assert (/webapp/node_modules/supertest/lib/test.js:203:12)",
|" at assert (/webapp/node_modules/supertest/lib/test.js:132:12)",
|" at /webapp/node_modules/supertest/lib/test.js:129:5",
|" at Test.Request.callback (/webapp/node_modules/superagent/lib/node/index.js:781:12)",
|" at ClientRequest.<anonymous> (/webapp/node_modules/superagent/lib/node/index.js:736:10)",
|" at ClientRequest.emit (events.js:95:17)",
|" at Socket.socketOnEnd [as onend] (http.js:1569:9)",
|" at Socket.g (events.js:180:16)",
|" at Socket.emit (events.js:117:20)",
|" at _stream_readable.js:944:16",
|" at process._tickCallback (node.js:448:13)"
There is this code on line 202 in supertest/lib/test.js
:
if (status) {
if (res.status !== status) {
var a = http.STATUS_CODES[status];
var b = http.STATUS_CODES[res.status];
return fn(new Error('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"'), res);
}
// remove expected superagent error
if (resError && resError instanceof Error && resError.status === status) {
resError = null;
}
}
On the line 203, which says if (res.status !== status) {
, res
is undefined. Because resError = { [Error: socket hang up] code: 'ECONNRESET', response: undefined }
.
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
On ECONNRESET, assert() calls undefined res.status which ...
On the line 203, which says if (res.status !== status) { , res is undefined. Because resError = { [Error: socket hang up]...
Read more >How do I debug error ECONNRESET in Node.js?
A break in the connection from the client throws the error ECONNRESET in Node. I believe this is intended functionality for Node, so...
Read more >Errors | Node.js v19.3.0 Documentation
AssertionError s are a special class of error that can be triggered when Node.js detects an exceptional logic violation that should never occur....
Read more >node:internal/stream_base_commons - You.com | The AI ...
In this context, the EPIPE error probably means that you're trying to write to a socket that has been closed. Since the setInterval()...
Read more >Expect / Should - Chai Assertion Library
Chai is a BDD / TDD assertion library for [node](http://nodejs.org) and the browser that can be delightfully paired with any javascript testing framework....
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
It’s quite an old thread and it is closed, but I still encounter this issue. It is reproduced on Windows only and when I send a PUT with binary content with content-type set to a different value. After googling this is still the most relevant place, so maybe someone knows how to address this problem?
@mikelax - Do you know ETA for this fix; or know if supertest is working towards a fix?
My issue is similar to this : https://github.com/visionmedia/supertest/issues/298