Changeset 38238


Ignore:
Timestamp:
2023-09-27T21:02:34+13:00 (8 months ago)
Author:
anupama
Message:

Moving the handling of the silent gsdl_cgi errors (that result in perl die statements, but yet do not cause ajax error functions to be called, and the ajax success callback function is still called instead) to be processed at toplevel when first encountered: in javascript_global_functions.js::_callMetadataServer() and gsajaxapi.js::urlPostAsync and gsajaxapi.js::urlPostSync(). The latter two are untested, but I think (something like) this is needed there as well. Basically, if no errorcallback is registered, we see an alert message popup with the otherwise silent error message displayed. If an error callback is registered, then the silent error message is at least printed to console, and the errorcallback can handle the rest as the coder chooses.

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/gsajaxapi.js

    r32873 r38238  
    203203    //alert(scriptURL + "?" + params);
    204204    //alert(xmlHttp.responseText); // if synchronous, process xmlHttp.responseText AFTER send() call
     205    if(xmlHttp.status != 200
     206       || xmlHttp.responseText.indexOf("ERROR: ") !== -1
     207       || xmlHttp.responseText.indexOf("<Error>") !== -1)
     208    {
     209        var errorMsg = "callingFunction Failed with";
     210        if(xmlHttp.status == 200) {
     211        errorMsg += " gsdlCGI error";
     212        }
     213        errorMsg += ":\n" + xmlHttp.responseText;
     214       
     215        console.log(errorMsg);
     216    }
     217   
    205218    return xmlHttp.responseText;
    206219    }
     
    208221    // New, an Ajax Asynchronous Post method.
    209222    // For helpful links, see the urlPostSync() method above
    210     this.urlPostAsync = function(scriptURL, params, callback) {
     223    this.urlPostAsync = function(scriptURL, params, callback, errorCallback) {
    211224    var xmlHttp=false;
    212225    try {
     
    264277        xmlHttp.onreadystatechange=function() {
    265278        if(xmlHttp.readyState==4) {
    266             callback(xmlHttp); // e.g. this might do: updatepage(xmlHttp.responseText);
     279            // Original behaviour of this block was just this single line:
     280            //callback(xmlHttp); // e.g. this might do: updatepage(xmlHttp.responseText)
     281
     282            var errorMsg = "callingFunction Failed with";
     283           
     284            // if a proper ajax error is detected, then call any errorCallback
     285            if(xmlHttp.status != 200 && errorCallback != null) {
     286            errorMsg += ":\n" + xmlHttp.responseText;
     287            alert(errorMsg);
     288            console.log(errorMsgPrefix);
     289           
     290            errorCallback(xmlHttp);
     291            }
     292           
     293            // Check for silent errors (gsdl_cgi->generate_error causes a silent die)
     294            // and alert user then call any errorCallback
     295            else if(xmlHttp.responseText.indexOf("ERROR: ") !== -1
     296               || xmlHttp.responseText.indexOf("<Error>") !== -1)
     297            {
     298            errorMsg += " gsdlCGI error:\n" + xmlHttp.responseText;
     299            alert(errorMsg);
     300            console.log(errorMsg);
     301           
     302            if(errorCallback != null) {             
     303                errorCallback(xmlHttp);
     304            } else { // if silent error and no errorCallback, resort to sole callback
     305                 callback(xmlHttp);
     306            }
     307            }
     308
     309            else {
     310            // if either success, Or error status but there's no error callback,
     311            // or if no silent die on error, then call default callback
     312            callback(xmlHttp); // e.g. this might do: updatepage(xmlHttp.responseText);
     313            }
    267314        }
    268315        }
  • main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js

    r38234 r38238  
    555555        //var xml = $.parseXML(response);
    556556        //console.log(xml);
     557
     558
     559        // Handle the otherwise silent die statement of gsdl_cgi->generate_error(),
     560        // forcing the errorResponseFunction route in such a case
     561        if(response.indexOf("ERROR: ") !== -1 || response.indexOf("<Error>") !== -1) {
     562            if(errorResponseFunction != null) {         
     563            console.log("(" + callingFunction + ") Failed with gsdlcgi error:\n" + response);
     564            errorResponseFunction(response);
     565            } else {
     566            alert("(" + callingFunction + ") Failed\n" + response);
     567            console.log("(" + callingFunction + ") Failed\n" + response);
     568            }
     569           
     570        }
    557571       
    558         if(successResponseFunction != null) {
     572        else if(successResponseFunction != null) {
    559573            //console.log("XXXX callMetaServer - Got response: " + response);
    560574            successResponseFunction(response);
     
    563577        .fail(function(response) {
    564578            if(errorResponseFunction != null) {
    565                 errorResponseFunction(response);
     579                console.log("(" + callingFunction + ") Failed\n" + response);   
     580                errorResponseFunction(response);
    566581            } else {
    567                 console.log("(" + callingFunction + ") Failed");
     582                    alert("(" + callingFunction + ") Failed\n" + response);
     583                console.log("(" + callingFunction + ") Failed\n" + response);
    568584            }
    569585        });
     
    584600   
    585601    if(async_setting) {
    586         gsapi.urlPostAsync(url, params, successResponseFunction);
     602        gsapi.urlPostAsync(url, params, successResponseFunction, errorResponseFunction);
    587603    } else {
    588604        ajaxResponse = gsapi.urlPostSync(url, params);
    589         ajaxResponse = ajaxResponse;
     605        //ajaxResponse = ajaxResponse;
    590606    }
    591607   
  • main/trunk/greenstone3/web/interfaces/default/js/user_comments.js

    r38237 r38238  
    461461    var result = (data.responseText) ? data.responseText : data;       
    462462
     463    /*
    463464    // check for gsdl_cgi->generate_error() result, which ends up in a silent die statement
    464465    // unless we look for it in the "success" result, in the form of a message starting
     
    468469    return;
    469470    }
     471    */
    470472   
    471473    //console.log("@@@ Done removing metadata:\n" + result);
Note: See TracChangeset for help on using the changeset viewer.