Answers for "fetch then catch finally"

2

try catch fetch

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
  })
  .then( json => {
    this.props.dispatch(doSomethingWithResult(json)) 
  })
  .catch( err => {
    err.text().then( errorMessage => {
      this.props.dispatch(displayTheError(errorMessage))
    })
  })
Posted by: Guest on March-15-2021
0

axios fainally

.finally(function() {
   // settled (fulfilled or rejected)
});
.finally(()=> {
   // settled (fulfilled or rejected)
});
Posted by: Guest on July-02-2020

Browse Popular Code Answers by Language