fetch(): Getting exception information instead of "TypeError: Failed to fetch"

Viewed 25

I'm using the fetch() API to fetch HTTP requests. Some of these fail, for various reasons. In my fetch() chain, I want to catch the errors, therefore I have:

fetch(uri).then(function(response) {
    console.log("ok", response);
}).catch(function(error) {
    console.log("error", error);
});

I expect to get detailed information about this (e.g., the Exception that caused the catch block to be called). However, all I am getting is the text string "TypeError: Failed to fetch" passed as the "error" variable.

In the console, there is more info, for example: POST https://myurl net::ERR_CERT_AUTHORITY_INVALID, letting me know that this request failed because no TLS connection could be established becuase the certificate is bad. I want that specifity in my code so I can react properly, but all I am getting is the nondescript "TypeError" text message.

How do I get more detail in the fetch() error handler?

0 Answers
Related