title: Determine if ajax call failed due to insecure response or connection refused
body: <p>I've been doing a lot of research and could not find a way to handle this. I'm trying to perform a jQuery ajax call from an https server to a locahost https server running jetty with a custom self signed certificate. My problem is that I cannot determine whether the response is a connection refused or a insecure response (due to the lack of the certificate acceptance). Is there a way to determine the difference between both scenarios? The <code>responseText</code>, and <code>statusCode</code> are always the same in both cases, even though in the chrome console I can see a difference:</p>
  
  <pre><code>net::ERR_INSECURE_RESPONSE
  net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p><code>responseText</code> is always "" and <code>statusCode</code> is always "0" for both cases.</p>
  
  <p>My question is, how can I determine if a jQuery ajax call failed due to <code>ERR_INSECURE_RESPONSE</code> or due to <code>ERR_CONNECTION_REFUSED</code>?</p>
  
  <p>Once the certificate is accepted everything works fine, but I want to know whether the localhost server is shut down, or its up and running but the certificate has not yet been accepted.</p>
  
  <pre><code>$.ajax({
      type: 'GET',
      url: "https://localhost/custom/server/",
      dataType: "json",
      async: true,
      success: function (response) {
          //do something
      },
      error: function (xhr, textStatus, errorThrown) {
          console.log(xhr, textStatus, errorThrown); //always the same for refused and insecure responses.
      }
  });
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Ei30M.jpg" alt="enter image description here"></p>
  
  <p>Even performing manually the request I get the same result:</p>
  
  <pre><code>var request = new XMLHttpRequest();
  request.open('GET', "https://localhost/custom/server/", true);
  request.onload = function () {
      console.log(request.responseText);
  };
  request.onerror = function () {
      console.log(request.responseText);
  };
  request.send();
  </code></pre>