Thursday, October 01, 2009

Flex Client Side Error Handling with Domino...

Handling errors within the context of Flex poses a few challenges.

  1. Errors are generated on the client. Your server and logs have no idea that a user experienced an error within the flash runtime
  2. No "out of the box" way to post the errors back to our favorite application server (Domino)
The way I chose to handle solving this problem was via a custom event. This custom event (LogError) gives you the ability to post the error to the server thus enabling you to view the errors in a central location, and dispatch that an error occurred throughout the rest of your application. Dispatching the LogError enables the developer to manage the view state of the application if something blows up during a critical process or method call (i.e. disable a button, or a data grid, load a popup to gain user input on what the user was doing etc...). The LogError custom event uses the Rest class to post the stack trace, or any other information needed. I've added the LogError custom event to the FlexContacts project, along w/ a Logger lotuscript class to consume the posted data and drop it into a notes document. Over time, as I find new techniques developing flex w/ domino, I will be building these elements out into the FlexContacts project (sort of as a running example for anyone interested).

Let's take a look at how a developer would call the LogError custom event in a method (located in contact form and called by Test Error button):

private function blowUp():void{
try{
//generate a null pointer..
var o:Object;
o.someAttribute="test";

}catch(err:Error){
var logErr:LogError = new LogError(LogError.EVENT_TYPE);
//this posts the log to the server.
logErr.log("FlexContacts.mxml","blowUp",err.getStackTrace());
//here choose to dispatch the log event that occured to any event listeners.
this.systemManager.dispatchEvent(logErr);
}
}


The processing sequence for the above is as follows:
  1. Exception occurs
  2. LogError posts the log to the domino server (via http/s)
  3. A notes form captures the posted log data (fmLog)
  4. A WebQuery save agent HandleFlexError is called from the form to append the log
  5. The agent calls a LotusScript object called FlexError
  6. FlexError creates a log entry on the back end notes doc which looks like:
User Id:
888888
Date Created:
02/08/2009 04:00 PM

Type:
FLEX_ERROR

Log(s):
FlexContacts.mxml.blowUp 2/8/2009 4:00:45 PM TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.notesui::ContactForm/blowUp()
at com.notesui::ContactForm/__btnTestErrorLog_click()


That is it... Flex's ability to easily make HTTP POSTS/GETS makes logging client side errors a snap. Please feel free to download the updated FlexContacts project from here. If you need tips on how to deploy, please see the previous blog entry on FlexingDomino...Also if you have any questions please feel free to post comments on this blog.

cheers,

Mark

No comments: