Moved source into dedicated directory.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function fetchItem(url, attempt) {
|
||||
function retry(error) {
|
||||
console.log(error);
|
||||
|
||||
if(attempt < 3) {
|
||||
console.log('Retrying...');
|
||||
|
||||
return fetchItem(url, ++attempt);
|
||||
}
|
||||
};
|
||||
|
||||
return fetch(url).then(res => {
|
||||
return res.ok ? res : Promise.reject(`Failed to fetch ${url}`);
|
||||
}).then(res => {
|
||||
console.log(`Fetched '${url}'`);
|
||||
|
||||
return res.body;
|
||||
}).catch(retry);
|
||||
};
|
||||
|
||||
module.exports = fetchItem;
|
||||
Reference in New Issue
Block a user