Wednesday, October 23, 2013

How to Log Errors in SharePoint Hosted Apps?

It is most common thing to log error message if some exception occurs within the code, so that user can find out what causing the error. It is straight forward if you using Server side object model. Since Hosted apps only use JavaScript object model and its bit new to many of us, not sure which namespace/class to use.

 

We use SP.Utilities.Utility.logCustomAppError method to log the app errors. Following is the sample code

 

 

function onFail(sender, args) {

    logAppError(args.get_message() + '\n' + args.get_stackTrace());
}

function logAppError(message) {
    SP.Utilities.Utility.logCustomAppError(context, message);
    this.context.executeQueryAsync();
}

0 comments:

Post a Comment