JSDO properties, methods, and events reference : afterAddCatalog event
  

afterAddCatalog event

Fires when the addCatalog( ) method on the current Session object completes execution after it was called asynchronously.
Applies to:progress.data.Session class
The following parameters appear in the signature of any event handler (callback) function (or functions) that you subscribe to this event:

Syntax

function ( login-session , result , error-object )
login-session
A reference to the Session object that fired the event.
result
A numeric constant that the addCatalog( ) method returns when called synchronously. Possible constants include:
*progress.data.Session.SUCCESS — The specified Data Service Catalog loaded successfully.
*progress.data.Session.CATALOG_ALREADY_LOADED — The specified Data Service Catalog did not load because it is already loaded.
*progress.data.Session.AUTHENTICATION_FAILURE — The Catalog failed to load because of a user authentication error.
*progress.data.Session.GENERAL_FAILURE — The specified Catalog failed to load because of an error other than an authentication failure.
This value can also be returned if invalid user credentials triggered a Catalog access timeout according to the value of the addCatalog( ) method's parameter-object.iOSBasicAuthTimeout property.
For all other non-authentication errors, this event returns an Error object reference as error-object. For more detailed information about any response (successful or unsuccessful) returned from the web server, you can also check the XMLHttpRequest object (XHR) returned by the lastSessionXHR property.
If error-object is not null, result will be null.
error-object
A reference to any Error object that might have been thrown as login-session processed the addCatalog( ) method response. This value can be null. If it is not null, result will be null.
Note: If this object is thrown because of a Catalog access timeout triggered according to the value of the addCatalog( ) method's parameter-object.iOSBasicAuthTimeout property, the message property of the error object is set to "addCatalog timeout expired".
Note: These callback parameters provide the same information that is available after a synchronous invocation of addCatalog( ).
Application code can subscribe a callback for this event by invoking the subscribe( ) method on a Session object.

Example

The following code fragment subscribes the function, onAfterAddCatalog, to handle the afterAddCatalog event fired on the session, empSession, after the addCatalog( ) method is called asynchronously. The event callback checks for either expected success and failure return values, or a thrown Error object with an unknown error, and assembles an appropriate message to display in an alert box for each case:
var retValue;
empSession.subscribe('afterAddCatalog', onAfterAddCatalog);

retValue = empSession.addCatalog( {
catalogURI : "http://testmach:8980/SportsMobileApp/static/OrderEntrySvc.json",
async : true } );
/* ( retValue is progress.data.Session.ASYNC_PENDING ) */


/* invoked by empSession when it processes the response from getting the Catalog
from the web application */
function onAfterAddCatalog( pdsession, addCatalogResult, errorObject ) {
var msg;

if (addCatalogResult === progress.data.Session.LOGIN_AUTHENTICATION_FAILURE ) {
alert("Add Employee Catalog failed: Authentication error");
}
if (addCatalogResult === progress.data.Session.GENERAL_FAILURE ) {
alert("Add Employee Catalog failed: Non-authentication error");
}
else if (addCatalogResult ) { // Either SUCCESS or CATALOG_ALREADY_LOADED
alert("Catalogs loaded.");
}
else { // errorObject likely returns other non-authentication error info
if (errorObject) {
msg = ‘\n’ + errorObject.message;
}
alert("Unexpected addCatalog error: " + msg);
}
};

See also:

addCatalog( ) method (Session class), lastSessionXHR property, subscribe( ) method (Session class)