Moved source into dedicated directory.

This commit is contained in:
2024-09-11 05:16:53 +02:00
parent 95fdf59e6f
commit 2b9801999b
18 changed files with 0 additions and 0 deletions
+25
View File
@@ -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;