0

I'm writing a Chrome extension. In the background page script I have:

function httpGetAsync(theUrl, callback)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
               callback(xmlHttp.responseText);
            } else {
                console.log("Error: ", xmlHttp.statusText);
            }
    };
    xmlHttp.open('GET', theUrl, true); // true for asynchronous 
    try {
        xmlHttp.send(null);
    } catch (err) {
        console.log("Caught Error");
    }
}

When the server for the URL is down, I get an exception on the JavaScript console 'net::ERR_CONNECTION_REFUSED'. I want to catch the exception so it does not appear on the console, not just get the "Error:" printed. Note that this question is NOT answered in the "Duplicated to" question".

Craig S. Anderson
  • 6,966
  • 4
  • 33
  • 46

0 Answers0