Where the error handling functions ever built into the main file?

Jun 1 at 2:10 PM
I'm talking about these

// PURPOSE:
//  Examines SPServices xData.responseXML for any errors. At a minimum, it will use this SP.UI framework to display
//  an error summary in the status bar which can include the name of your function and the SPServices operation for 
//  troubleshooting in the field and debugging during development. Optionally, it dumps the verbose output from 
//  $().SPServices.SPDebugXMLHttpResult() to a supplied container
//
// NOTE:
//  It is possible for the "Status" parameter in the completefunc() callback to state "success" and for
//  xData.statusText to hold "OK" when in fact there are errors. A "Status" of "success" simply means the web 
//  service call succeeded. It does NOT mean the web service did not return its own error code and message.
//
// USAGE:
//  $(xData).OutputSPError();
//
jQuery.fn.OutputSPError = function(options) {

    var opt = $.extend({}, {
        functionName:   "",             // Name of your javascript function that invoked the SPServices call
        operationName:  "",             // Name of the SPServices operation, ie: "UpdateListItems"
        msgContainer:   "#SPServices",  // [OPTIONAL] jQuery selector for HTML container to hold error messages output
        }, options);
    
    // Ensure we were chained to the right object
    if( typeof($(this).prop("responseXML")) === "undefined" )
        return;

    var responseXML = $(this).prop("responseXML");
    if( !$(responseXML).hasSPError() )
        return;
    
    var statusText  = $(this).prop("statusText");
    var message = "";

    if( opt.functionName != "" || opt.operationName != "" )
        message = "[" + opt.functionName + "] " + opt.operationName + " :: ";

    // Display the error summary in the status bar
    var strStatusID = 
        SP.UI.Status.addStatus(
            "<img src='/_Layouts/Images/error16by16.gif' align='absmiddle'>&nbsp;" + 
            message + (statusText != "OK" ? statusText + ":&nbsp;" : "" ) + $(responseXML).getSPErrorText());
    SP.UI.Status.setStatusPriColor(strStatusID, "yellow");

    // Dump the error details to the caller's message container and unhide it
    if( $(opt.msgContainer).length != 0 ) {
        var errorDetails    = $().SPServices.SPDebugXMLHttpResult({node: responseXML});
        var divStatus       = jQuery("<h1 class='_wsStatusText'></h1>").appendTo(opt.msgContainer);
        var divError        = jQuery("<div class='_wsError'></div>").appendTo(opt.msgContainer);
        $(divStatus).text((statusText != "OK" ? statusText : $(responseXML).getSPErrorCode()));
        $(divError).append("<b>" + message + "</b><br>" + errorDetails);
        $(opt.msgContainer).show();
    }
    return;
}


// PURPOSE:
//  Given an XML message as returned by the Sharepoint web services API, this method checks for an error
//
// RETURNS:
//  {Boolean} true|false
//
// USAGE:
//  $(xData).hasSPError();
//  $(xData.responseXML).hasSPError();
//
jQuery.fn.hasSPError    = function() {

    // Sometimes a web service will be reachable and the web method will still
    // return an error code XML node. So we need to check its contents
    return( $(this).getSPErrorCode() != "0x00000000");
};/* jQuery.fn.hasSPError() */



// PURPOSE:
//  Given an XML message as returned by the Sharepoint web services API, this method
//  checks if it contains an error and returnS the error code.
//
// NOTE:
//  Sometimes a web service will be reachable and the web method call will succeed with no errors
//  but it may still return an error code XML node. If so, the node value needs to be checked.
//  EXAMPLE: UpdateListItems returns "0x00000000" for success
//
// RETURNS:
//  {String} hexidecimal error code
//
// USAGE:
//  $(xData).hasSPError();
//  $(xData.responseXML).hasSPError();
//
jQuery.fn.getSPErrorCode    = function() {

    if( typeof($(this).prop("status")) !== "undefined" && $(this).prop("status") != 200 )
        return $(this).prop("status").toString();
    
    var responseXML = $(this).prop("responseXML");
    if( typeof($(this).prop("responseXML")) === "undefined" )
        responseXML = $(this);

    var spErrCode = $(responseXML).find("ErrorCode:first");
    if( spErrCode.length )
        return spErrCode.text();
    
    spErrCode = $(responseXML).find("errorcode:first");
    if( spErrCode.length )
        return spErrCode.text();
    
    spErrCode = $(responseXML).find("faultcode");
    if( spErrCode.length )
        return spErrCode.text();
    
    return "0x00000000";
};/* jQuery.fn.hasSPError() */



// PURPOSE:
// Given a sharepoint webservices response, this method will look to see if it 
// contains an error and return that error formated as a string.
//
// RETURNS:
//  {String} error message text
//
// USAGE:
//  alert($(xData).getSPError());
//  alert($(xData.responseXML).getSPError());
//
jQuery.fn.getSPErrorText    = function(){

    var responseXML = $(this).prop("responseXML");
    if( typeof($(this).prop("responseXML")) === "undefined" )
        responseXML = $(this);

    var errorText   = "Call to Sharepoint web services failed. ";
    
    if( $(responseXML).find("ErrorCode:first").text().length ) {
        errorText += "\n" + $(responseXML).find("ErrorCode:first").text()
            +   ": " + $(responseXML).find("ErrorText").text();
    } else if( $(responseXML).find("faultcode").length ) {
        errorText += $(responseXML).find("faultstring").text()
            + "\n" + $(responseXML).find("errorstring").text();
    } else {
        errorText = "";
    }
    return errorText;
}/* jQuery.fn.getSPError() */
Coordinator
Jun 8 at 1:45 PM
SimK:

No, I don't recognize this code. If you'd like to issue a pull request on GitHub, I can take a look at it:
https://github.com/sympmarc/SPServices

Note that the errors from the SOAP services are all over the place. It looks like this might be helpful for the most common operations like GetListItems, but it probably wouldn't help much with most of the other operations.

M.
Jun 8 at 2:39 PM
It's actually an existing working item

https://spservices.codeplex.com/workitem/10290

This is the initial discussion it was from

http://spservices.codeplex.com/discussions/393036

ptavares came up with it so it's probably really good :P
Jun 8 at 5:04 PM
Not sure about really good :-) , but yes, I recognize these. I use them still today in SPWidgets.

Paul
-- sent from mobile
Jun 8 at 5:08 PM
Marc: I'll see if I get an opportunity this weekend to send pull request - unless someone else submits it.

They are here: https://github.com/purtuga/SPWidgets/tree/master/src/sputils

Paul
-- sent from mobile