Austin Maier
Austin Maier

Reputation: 49

catch NS_ERROR_FAILIURE in Firefox

I'm using Topaz Signature pads & implementing their new AJAX library. I want to display a warning on the page if the page if the driver/service is not installed/running. To do this, the script makes a get request to a domain which redirects to localhost via the hosts file.

If the service is running, I get the status of the signature pad & everything is fine. If however, the service is not installed or not running, I just get NS_ERROR_FAILURE and the script halts, even if I'm within try{code}catch(err){errorcode}

try {
    console.log('connect: ' + TabletConnectQuery());
}
catch(err){console.log('Caught ' + err);}

My console just shows:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://tablet.sigwebtablet.com:47290/SigWeb/TabletState. (Reason: CORS request failed).    
Line 0
NS_ERROR_FAILURE: 
https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js line 2 > eval
Line 151

This is particularly troublesome as it occurs during a page transition & stops the animation dead.

Upvotes: 1

Views: 1122

Answers (1)

Austin Maier
Austin Maier

Reputation: 49

I ended up getting it to work by modifying the SigWebTablet.js library topaz provided.

Changed

function SigWebGetProperty(prop) {
    var xhr = SigWebcreateXHR();

    if (xhr) {
        xhr.open("GET", baseUri + prop, false );
        xhr.send(null);
        if (xhr.readyState == 4 && xhr.status == 200) {
            return xhr.responseText;
        }
    }
    return "";
}

To:

function SigWebGetProperty(prop) {
    var xhr = SigWebcreateXHR();

    if (xhr) {
        xhr.open("GET", baseUri + prop, false );
        try{
            xhr.send(null);
        }
        catch(err){
            return "";
        }
        if (xhr.readyState == 4 && xhr.status == 200) {
            return xhr.responseText;
        }
    }
    return "";
}

Upvotes: 1

Related Questions