pui.AjaxRequest suppressAlert property

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
jpmurtha
New User
Posts: 17
Joined: Thu Mar 12, 2015 6:33 pm
First Name: Jim
Last Name: Murtha
Company Name: Dealertrack
Contact:

pui.AjaxRequest suppressAlert property

Post by jpmurtha »

Dealertrack would like to be able to suppress the browser alert popup that displays when an invalid url is passed to pui.AjaxRequest.
[img]
DMSCORE-6285-3.jpg
DMSCORE-6285-3.jpg (12.74 KiB) Viewed 377 times
[/img]
Setting the suppressAlert property to true or false does not prevent this popup from showing. The javascript code is below

Code: Select all

Onload
var apiVersion = tripos.isAvailable("http://localhost:8080/api");
if (apiVersion !== null) {
    changeElementValue('version', apiVersion);
} else {
    changeElementValue('version', "triPOS not available");
}

/*
 * check for existance of triPOS restful API
 *
 * Will return a string containing the version of the triPOS api
 * or null which indicates some kind of error occurred and the
 * error details can be determined from variables
 * tripos_error_code and tripos_error_message.
 */
tripos.isAvailable = function(dtUrl) {
    var dtRequest, dtJsonResponse;
    tripos.resetError();

    // validate parameters
    if (dtUrl === null || dtUrl === undefined) {
        // null or missing url error
        tripos.setError("", "null or missing url parameter");
        return null;
    }

    dtRequest = new pui.AjaxRequest(dtUrl);

    if (dtRequest) {
        dtRequest.method = "GET";
        dtRequest.async = false;
        dtRequest.setRequestHeader('tp-application-id','3028');
        dtRequest.setRequestHeader('tp-application-version','1.0.0');
        dtRequest.setRequestHeader('tp-application-name','MyApplication');
        dtRequest.setRequestHeader('tp-authorization','Version=1.0, Credential=7c2dcd15-f327-462c-805e-0a4b7389a77a');
        dtRequest.setRequestHeader('accept', 'application/json');
        dtRequest.suppressAlert = false;

        dtRequest.send();

        if (dtRequest.getStatus() !== 200) {
            tripos.setError("", "http status " + dtRequest.getStatus());
            return null;
        } else {
            dtJsonResponse = JSON.parse(dtRequest.getResponseText());
            if (dtJsonResponse) {
                return dtJsonResponse._links[0].rel;
            } else {
                // json parsing error
                tripos.setError("", "error parsing api service response!");
                return null;
            }
        }
    } else {
        // error creating pui.AjaxRequest
        tripos.setError("", "error creating pui.AjaxRequest!");
        return null;
    }
};
jpmurtha
New User
Posts: 17
Joined: Thu Mar 12, 2015 6:33 pm
First Name: Jim
Last Name: Murtha
Company Name: Dealertrack
Contact:

Re: pui.AjaxRequest suppressAlert property

Post by jpmurtha »

Here is the solution that I came up with. Had the idea to handle the exception in my code instead of letting it be handled by genie. Put code in a try catch as follows and it the browser popup no longer displays.
try {
dtRequest.send();
}
catch(error) {
return null;
}
User avatar
Alex
Profound Logic Staff Member
Posts: 233
Joined: Fri Jan 04, 2008 12:10 pm
First Name: Alex
Last Name: Roytman
Company Name: Profound Logic Software
Contact:

Re: pui.AjaxRequest suppressAlert property

Post by Alex »

Yes, this is a good solution.

The suppressAlert property prevents alerts of unsuccessful AJAX requests, but it does not suppress JavaScript errors; which, in this case are reported by the onload event rather than the pui.AjaxRequest() class.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests