Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Error handling #3

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Velan commented Aug 1, 2013

Hello Mathias!

I have been using node-unshorten for a couple of weeks to parse urls on my twitter feed. But I keep getting every now and then some domains that cannot be properly resolved ( human error, DNS issue, ... ) and the request throws an error.

Anyway, as there is no error handler, my whole application crashes, restarts automatically and tries to unshorten the same faulty url until my twitter limit is hit. So I've basically added one for these cases while I'm strengthening other parts of my application.

Here's one example of a faulty url: http://alturl.com/5d4pq ( it seems to be a DNS issue, so it actually might work properly for you ), but any non existing domain will probably cause the same issue.

If you're interested I can open a pull request.

Cheers,

Velan.

Owner

mathiasbynens commented Jul 29, 2013

Here's one example of a faulty url: http://alturl.com/5d4pq ( it seems to be a DNS issue, so it actually might work properly for you ), but any non existing domain will probably cause the same issue.

Yeah, it does work for me. Strange!

Wouldn’t it be possible to just wrap the call to unshorten() in a try-catch in your own code? Or do you this is something that unshorten itself should take care of?

Velan commented Jul 29, 2013

Wrapping it in a try - catch would certainly work for me now that I know where the issue was. ;)

But other people could face the same issue in the future and unfortunately, the error returned by node is quite confusing and it took me quite a few minutes to track down where the problem was coming from as I was looking for a problem in other parts of my application that seemed more likely. ;)

Here's the error thrown by node:

        throw er; // Unhandled 'error' event
              ^
Error: getaddrinfo ENOTFOUND
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

It's quite confusing as there's no way to tell quickly where in the application was the error thrown and what's actually causing the issue. While handling the error directly on the request object does both. :)

Owner

mathiasbynens commented Jul 31, 2013

Okay then, feel free to send over that patch :) Thanks!

Velan commented Aug 1, 2013

All right!

I'll do that later today when I get home. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment