Skip to content

Instantly share code, notes, and snippets.

@t-book
Last active January 17, 2019 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-book/10ad30b317ca1487d1d7ff77f9a34eab to your computer and use it in GitHub Desktop.
Save t-book/10ad30b317ca1487d1d7ff77f9a34eab to your computer and use it in GitHub Desktop.
Check thumbs js fetch
function handleErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
let thumbs = [];
fetch("http://master.demo.geonode.org/api/layers/")
.then(r => r.json()).then(data => {
thumbs = data.objects.map(x => [ x['title'],x['thumbnail_url'] ])
})
.then(data => {
for (let i in thumbs) {
fetch(thumbs[i][1]).then(handleErrors).then(function(response) {
console.log(`${i} OK: ${thumbs[i][0]}`);
}).catch(function(error) {
console.warn(`${error} ${thumbs[i][0]}`);
});
}
})
.catch(e => console.log(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment