Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a timeout parameter to the request just in case that

yql servers are ... funny ;)
  • Loading branch information...
commit 45c040fe34160930d3874709f5d55a9ddaf0479c 1 parent d92b10f
@arcturus arcturus authored
Showing with 20 additions and 6 deletions.
  1. +20 −6 lib/yql.js
View
26 lib/yql.js
@@ -41,15 +41,29 @@ YQL.exec = function(yqlQuery, callback, params, httpOpts) {
// Delete httpOpts.ssl as we already reassigned it and don't want stray HTTP headers
delete httpOpts.ssl;
+ var timeout = httpOpts.timeout || null;
+ if (timeout) {
+ delete httpOpts.timeout;
+ }
+
+ var options = {
+ headers: httpOpts,
+ json: true,
+ method: 'GET',
+ url: url.parse((ssl == true ? 'https': 'http') + '://' + host + path + '?' + queryString)
+ };
+
+ // Add timeout (in milliseconds) if present in the options
+ if (timeout) {
+ options.timeout = parseInt(timeout);
+ }
+
// Execute the YQL request and fire the callback
- request({
- headers: httpOpts,
- json: true,
- method: 'GET',
- url: url.parse((ssl == true ? 'https': 'http') + '://' + host + path + '?' + queryString)
- }, function(error, response, body) {
+ request(options, function(error, response, body) {
if (!error) {
if (callback) callback((body));
+ } else if (error && error.code == 'ETIMEDOUT') {
+ if (callback) callback(error.code);
}
else {
throw 'Something went wrong with an HTTP request';
Please sign in to comment.
Something went wrong with that request. Please try again.