1

I have a custom monitor code setup. I need to check if the specified URL has its SSL certificate expired. Is there a specific HTTP code for this? For example:

(async() => {
    const res = await fetch('http://example.com');
    // Or `statusText`
    if (res.status == some_ssl_expiryCode) {
        console.log('SSL expired!');
    }
})();

Is there a way to do this in javascript?

Michael M.
  • 10,486
  • 9
  • 18
  • 34
K.K Designs
  • 688
  • 1
  • 6
  • 22

2 Answers2

2

As @Jasen said, the connection doesn't reach the server. The fetch request returns the error CERT_HAS_EXPIRED or CERT_INVALID. It does not produce an HTTP code. See the javascript code below.

fetch('https://example.com/')
    .then(res => res.text())
    .then(() => { /* Do something if success */ })
    .catch(error => {
        console.error(error);
        if (error.code === 'CERT_HAS_EXPIRED') {
            // Certificate has expired
        } else if (error.code === 'CERT_INVALID') {
            // Certificate is invalid
        }
    });
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
K.K Designs
  • 688
  • 1
  • 6
  • 22
1

The client application receives an HTTP 400 - Bad request response with the message "The SSL certificate error".

devnet
  • 19
  • 2