Meaningful UI Errors - Solution approach using Spring BlazeDS Integration and custom Exception Translator

</meta> </meta> </meta> </meta>

Spring BlazeDS Integration comes with the notion of custom exception translators. The translator makes sure that exceptions thrown from the Spring-exposed LCDS/BlazeDS destinations are converted to meaningful exceptions for the client, all of this far away from the service code which will be far more simple and clean.

</meta> </meta> </meta> </meta>

 

Server-Side Handling

In order to propagate useful information back to the Flex client when an exception occurs on the server, the original exception must be translated into an instance of flex.messaging.MessageException.

The translation logic can be provided by implementaion of org.springframework.flex.core.ExceptionTranslator interface.

</meta> </meta> </meta> </meta>

The custom exception translator role is to extract the Throwable, translate it to MessageException and throw it further.

 

This Java class is part of the BlazeDS and it will be deserialized using the class mx.messaging.messages.ErrorMessage (obtained from the event.message property).You can add your custom data in the MessageException class using the extended property.

</meta> </meta> </meta> </meta>

Client-Side Handling

Enforce the mechanism using Cairngorm MVC Framework.

Each operation in Cairngorm framework(for example) uses the ICommand and the IResponder interfaces to invoke the server. The IResponder interface has the fault method in case of errors.

By implementing a BaseCommand which all commands will extend. The BaseCommand will have a default implementation of the fault method. In case of Error it will invoke the ErrorViewer Component with the relevant parameters you would like to display to your end users(severity, message, stack trace...)

this code would look like:

    public function fault(info:Object):void    {
            var event:FaultEvent =  FaultEvent(info) ;
            var em:ErrorMessage = ErrorMessage(event.message);
            //extract extended data parameters
            var extendedData:HashMap = extractExtendedData(em.extendedData);
            var debugEnabled:Boolean = (String(extendedData.getValue("debug"))== "true");
            if (em.faultCode=="Channel.Call.Failed") {
                errorViewer.show("Cannot connect to the server ","", "",event.fault.getStackTrace(),false,closeApplication);
            }else if (em.faultCode=="Server.Processing.DuplicateSessionDetected"){
                errorViewer.show("Your session has expired. \nPlease login again", "", "",event.fault.getStackTrace(),false,closeApplication);
            }else
                errorViewer.show(em.faultString, extendedData.getValue("severity"), extendedData.getValue("stackTrace") ,debugEnabled);
        }

 

</meta> </meta> </meta> </meta>

ErrorViewer                                                                    

Singleton Flex component composed from pop-up window which will display a human readable error message. The show method takes the relevant parameters and display it.

 

 

The over-all process in a diagram:


 

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com