Skip to content Skip to sidebar Skip to footer

Error Handling In Http Ajax Call Using $fetch Javascript

I tried to handle the Network related issues in HTTP ajax call. So, I temporarily stopped the respective API's service in IIS and I tried to call the shut downed API - http://local

Solution 1:

Based on this issue on Github, you can try to identify error types in catch block instead. So, something like this may work for your case:

fetch("http://localhost:1000/GetData")
  .then(response => {
    alert("Super");
    return response.json();
  })
  .catch(err => {
    const errStatus = err.response ? err.response.status : 500;
    if (errStatus === 404){
      // do something
    } else {
      // do another thing
    }
  });

Post a Comment for "Error Handling In Http Ajax Call Using $fetch Javascript"