Throw 429 errors

This commit is contained in:
patrickkfkan 2021-02-16 19:47:57 +08:00
parent eaa9a73812
commit 533d1cadcd

View File

@ -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();
}
});
});
}