Silly code blocks
json fetcher
async function fetchJsonFromSources(sources) {
let lastError = null;
for (const source of sources) {
try {
const response = await fetch(source, { cache: "no-store" });
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return {
source,
json: await response.json()
};
} catch (error) {
lastError = error;
}
}
throw lastError || new Error("Source was not reachable.");
}