Tuesday, 30 November 2021

How to catch ERR_CERT_AUTHORITY_INVALID in javascript

The Web Application I am developing needs to fetch data from a number of different IOTs within the local network, e.g.,

const response = await fetch("https://192.168.0.245/api/auto/login", options);

Since it is an https connection, and each IOT carries a self-signed SSL cert, therefore, the fetch() above will throw an error "TypeError: Failed to fetch" (since the cert has not yet been accepted), and the application will show the following in the browser's console

OPTIONS https://192.168.0.245/api/auto/login net::ERR_CERT_AUTHORITY_INVALID

What I need is to be able to catch this error in javascript. Specifically I need to be able to catch different errors like ERR_CERT_AUTHORITY_INVALID, ERR_SSL_PROTOCOL_ERROR or ERR_CONNECITON_REFUSED... etc. so I can show different error messages accordingly.

Unfortunately the fetch() function always throw the same "TypeError: Failed to fetch" exception under all these three different errors above.

Is there anyway I can catch this specific ERR_CERT_AUTHORITY_INVALID exception?

Thank you.



from How to catch ERR_CERT_AUTHORITY_INVALID in javascript

No comments:

Post a Comment