diff --git a/lib/index.js b/lib/index.js index 78f19eb..56667c0 100644 --- a/lib/index.js +++ b/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(); + } + }); }); }