12

I am getting an unhandled error but not sure where it's coming from. My app has several http.request(options, callback).end() in different methods, with the callback's trapping "uncaughtException" and "error". I'd like to know which of my methods initiated this issue. Below is the error I get. It is random. Any ideas how to track this down? I was hoping for some global way of trapping unhandled errors.

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: read ECONNRESET
    at exports._errnoException (util.js:746:11)
    at TCP.onread (net.js:559:26)

2 Answers 2

25

ECONNRESET means that the other side of the TCP connection is aborted. You could look at the server logs, but since it was random times this makes me think that the server becomes overloaded and kills a few connections.

If you're starting a process at any point in the process try the below:

process.on('uncaughtException', function (err) {
  console.error(err.stack);
  console.log("Node NOT Exiting...");
});
Sign up to request clarification or add additional context in comments.

1 Comment

see my other comment above
5

attach a

request.on('error', function(err) {
    // Handle error
});

to your requests.

You can also catch uncaught errors for the process:

process.on('uncaughtException', function(err) {
  console.log('Caught exception: ' + err);
});

This error as it reads states the connection was reset, so its definitely one of the requests.

4 Comments

As I state in my posting, already been doing that. I am trying to find out if there is a global catchall errors (kind of like the old days of ON ERROR GOTO :)
And your program enters none of them?
Nope, does not enter any of them.
Try the library request-promise-json, i think it has better error handling, its on top of the default request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.