Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 2 contributors
Showing with 25 additions and 11 deletions.
  1. +25 −11 lib/yql.js
View
36 lib/yql.js
@@ -19,9 +19,9 @@ YQL.exec = function(yqlQuery, callback, params, httpOpts) {
}
// Default the optional args
- callback = callback !== undefined ? callback : false;
- params = params !== undefined ? params : {};
- httpOpts = httpOpts !== undefined ? httpOpts : { ssl: false };
+ callback = (callback !== undefined ? callback : false);
+ params = (params !== undefined ? params : {});
+ httpOpts = (httpOpts !== undefined ? httpOpts : { ssl: false });
var host = 'query.yahooapis.com',
path = '/v1/public/yql',
@@ -29,8 +29,8 @@ YQL.exec = function(yqlQuery, callback, params, httpOpts) {
ssl = httpOpts.ssl;
// Required YQL paramaters
- params.env = params.env !== undefined ? params.env : 'http://datatables.org/alltables.env';
- params.format = params.format !== undefined ? params.format : 'json';
+ params.env = (params.env !== undefined ? params.env : 'http://datatables.org/alltables.env');
+ params.format = (params.format !== undefined ? params.format : 'json');
params.q = yqlQuery;
// Construct the querystring
@@ -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';

No commit comments for this range

Something went wrong with that request. Please try again.