Throw 429 errors
This commit is contained in:
parent
eaa9a73812
commit
533d1cadcd
11
lib/index.js
11
lib/index.js
|
@ -405,7 +405,16 @@ async function searchLocation(params) {
|
|||
async function _fetchPage(url, json = false, fetchOptions = null) {
|
||||
return _cache.getOrSet('page', url + (json ? ':json' : ':html') + (fetchOptions ? ':' + JSON.stringify(fetchOptions) : ''), () => {
|
||||
const doFetch = fetchOptions ? fetch(url, fetchOptions) : fetch(url);
|
||||
return doFetch.then( res => json ? res.json() : res.text() );
|
||||
return doFetch.then( res => {
|
||||
if (res.status === 429) {
|
||||
const err = new Error('429 Too Many Requests');
|
||||
err.code = '429';
|
||||
throw err;
|
||||
}
|
||||
else {
|
||||
return json ? res.json() : res.text();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user