Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout error returns non-valid Javascript object #744

Open
jackspaniel opened this issue Sep 18, 2015 · 3 comments
Open

Timeout error returns non-valid Javascript object #744

jackspaniel opened this issue Sep 18, 2015 · 3 comments

Comments

@jackspaniel
Copy link

Maybe I am missing something here. But here is what I see in the err argument for a call that times out:

call.end(function(err, response) {
    console.log(err); // { [Error: timeout of 1ms exceeded] timeout: 1 }  
    console.log(JSON.stringify(err)); // {"timeout":1}
    console.log(typeof err); // object

It seems like the error message is somehow getting tacked onto the err object w/o a proper key?

@jackspaniel
Copy link
Author

Ok well a little further research shows all err objects looking similar:

call.end(function(err, response) {

    console.log(err); // { [Error: getaddrinfo ENOTFOUND xxxhttp] code: 'ENOTFOUND', errno: 'ENOTFOUND',  syscall: 'getaddrinfo',  hostname: 'xxxhttp' }

    console.log(JSON.stringify(err)); // {"code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo","hostname":"xxxhttp"}

    console.log(typeof err); // object

Basically I am trying to isolate timeout errors. Can I trust that if the timeout property exists in the error object, that means timeout error and nothing else? I don't really feel comfortable matching on err.toString() or something weird like that. And timeout is the only property in the err object.

Ideally it would be nice to have an error code like code; "TIMEOUT".

@jackspaniel
Copy link
Author

Ok well now I'm guessing you just overloaded the toString() method. Although I don't see that in the source code anywhere.

@codeviking
Copy link

I ran into this as well, but if you check this out...

https://github.com/visionmedia/superagent/blob/master/lib/client.js#L881

...depending on the existence of err.timeout appears to be reliable, I'm going with that for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants