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.

On ECONNRESET, `assert()` calls undefined `res.status` which throws an error

See original GitHub issue

When 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:closed
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
aidescommented, Aug 29, 2016

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?

0reactions
varunj90commented, Nov 24, 2015

@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

Read more comments on GitHub >

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

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