I'm working on a Web Application that requires fetching data from various IOT devices on the local network, for example:
const response = await fetch("https://192.168.0.245/api/auto/login", options);
Since this involves an https connection and each IOT device has a self-signed SSL certificate, the fetch() function throws an error "TypeError: Failed to fetch" (due to the certificate not being accepted), resulting in the following message appearing in the browser console:
OPTIONS https://192.168.0.245/api/auto/login net::ERR_CERT_AUTHORITY_INVALID
I need to be able to handle this error in JavaScript, specifically targeting different errors such as ERR_CERT_AUTHORITY_INVALID, ERR_SSL_PROTOCOL_ERROR, or ERR_CONNECTION_REFUSED, so that I can display appropriate error messages accordingly.
Unfortunately, regardless of the specific error, the fetch() function consistently throws the generic "TypeError: Failed to fetch" exception.
Is there any way to catch the specific ERR_CERT_AUTHORITY_INVALID exception?
Thanks.