I'm trying to fetch() a file, and if it fails, i want to try the alternative file.
This nested Promise() feels dirty. What is a better solution?
fetch('file1.csv')
.then(function(response){
if (response.status !== 200) {
throw 'file1 no 200 response';
}
return response;
})
.catch(function(){
return fetch('file2.csv')
.then(function(response){
if (response.status !== 200) {
throw 'file2 no 200 response';
}
return response;
})
})
.then(function(response){
console.log('got file1 or file2, continue... then() ...');
console.log(response);
})
.catch(function(err){
console.log('both files not found');
});