0

I have a problem when I throw that. It prints to the error to the console (when I check by changing the path to wrong path and I want to see if I treat errors).

what can I do?

It means that if the fetch gives an error, so it prints the error into the console too (and not just going to catch). And also if I will not throw something but the fetch will return an error (like 404), it will print in the console something like: Failed to load *path* resource: the server responded with a status of 404 () or GET *path* net::ERR_ABORTED 404

function f(path) {
     fetch(path)
        .then(response => {
            if (response.status != 200) {
                throw response.status;
            } else {
                return response;
            }
        })
        .then(response => response.json())
        .catch(error => {
          // treatment...
          });
}

Thank you.

ib2000
  • 43
  • 7

0 Answers0