Handling of JavaScript Try Catch Throw errors while utilizing the API fetch promise
JavaScript Promise Fetch API with error handling of try catch and throw. Below I explain with code, Fetch API use for request a remote network for request data.
const showRecipe = async function(){
try{
const res = await fetch('https://forkify-api.herokuapp.com/api/v2/recipes/5ed6604591c37cdc054bc886');
const data = await res.json();
if(!res.ok){
throw new Error(`${data.message} - ${res.status}`);
}
console.log(data);
}catch(err){
alert(err);
}
}
showRecipe();
