Answers for "how to catch reject in fetch api"

0

fetch catch

fetch(url).then((response) => {
  if (response.ok) {
    return response.json();
  } else {
    throw new Error('Something went wrong');
  }
})
.then((responseJson) => {
  // Do something with the response
})
.catch((error) => {
  console.log(error)
});
Posted by: Guest on March-17-2021

Browse Popular Code Answers by Language