node-yelp-api-v3
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -78,3 +78,3 @@ 'use strict'; | ||
clearInterval(interval); | ||
return reject(new Error('Token request timed out.')); | ||
return reject(new Error('Yelp fetch token request timed out.')); | ||
} | ||
@@ -98,3 +98,8 @@ time += 100; | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var tries = arguments[2]; | ||
if (!tries) { | ||
tries = 0; | ||
}; | ||
var promise = new Promise(function (resolve, reject) { | ||
@@ -104,2 +109,3 @@ var debug = params.debug; | ||
// If there is no access token, throw an error stating that | ||
if (!_this3.access_token) { | ||
@@ -111,2 +117,10 @@ return reject(new Error('Missing access_token')); | ||
if (err) { | ||
// Try three times on a 401 to refresh the access token | ||
// It seems they last for about three months before expiring | ||
if (tries < 3 && err.statusCode === 401) { | ||
return _this3.getAccessToken().then(function () { | ||
return _this3.makeReq(resource, params, tries); | ||
}); | ||
} | ||
return reject(err); | ||
@@ -113,0 +127,0 @@ } |
{ | ||
"name": "node-yelp-api-v3", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A promise-based JavaScript client for dealing with Yelp's API (v3).", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
122128
154
8