Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to get error using fetch API

function CheckError(response) {
  if (response.ok) {
    return response.json();
  } else {
    throw Error(response.statusText);
  }
}

// Now call the function inside fetch promise resolver
fetch(url)
  .then(CheckError)
  .then((jsonResponse) => {
  }).catch((error) => {
  });
 
PREVIOUS NEXT
Tagged: #error #fetch #API
ADD COMMENT
Topic
Name
9+6 =