I’m starting and one of the first things I’m trying on my own is how to add multiple sources to this promise:
const getTodos = async () =>{
const response = await fetch('todos/resource.json');
if(response.status !== 200){
throw new Error('Cannot fetch data');
}
const data = await response.json();
return data;
};
getTodos()
.then(data => console.log ('Resolved: ', data))
.catch(err => console.log ('Rejected', err.message);
I tried making different variables and using .then after to print them but that didn’t work.
const getTodos = async () =>{
const response = await fetch('todos/resource1.json');
if(response.status !== 200){
throw new Error('Cannot fetch data'); // Error from the source
}
const data = await response.json();
return data;
const response2 = await fetch('todos/resource2.json');
if(response2.status !== 200){
throw new Error('Cannot fetch data'); // Error from the source
}
const data2 = await response2.json();
return data2;
};
getTodos()
.then(data => console.log ('Resolved: ', data))
.then(data2 => console.log ('Resolved: ', data2))
.catch(err => console.log ('Rejected', err.message)) // Error for json file
;
any tips?