Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SmartGWT sending the error code and message to client side

    We are using SmartGWT Power Edition 3.0 to write web application and we want to have some exception handling on client side if server have exception. And we will have the code as following. And client side we plan to have error handler method (will call when STATUS_FAILURE is set) and I want to get back the Record that I set in server side in client side handler. But I can get one record but cannot found any attribute in the record, is there any missing...? or wrongly code?

    Following is the code segment for your reference

    Server Side
    Code:
    dsResponse = new DSResponse();
    dsResponse.setStatus(DSResponse.STATUS_FAILURE);
    Map params = new HashMap();
    params.put("errorCode", "10001");
    params.put("errorMsg", "The user have no authorization to read the data");
    dsResponse.setData(params);
    ClientSide
    Code:
    RPCManager.setHandleErrorCallback(new HandleErrorCallback(){
    	@Override
    	public void handleError(DSResponse response, DSRequest request) {
    		if (response.getStatus()<0) {
    
    			SC.say("Error Code --> " + Integer.toString(response.getStatus()));
    			com.allen_sauer.gwt.log.client.Log.error("#OfRecord:"+ Integer.toString(response.getData().length));
    			if ( response.getData().length > 0 ) {
    				Record r = response.getData()[0];
    				String [] ss = r.getAttributes();
    				for ( int i=0;i<ss.length;i++ ) {
    					com.allen_sauer.gwt.log.client.Log.error("Attribute:" + ss[i] + "  ---  value " + r.getAttributeAsString(ss[i]));
    				}
    			}
    		}
    	}
    });
    Result
    Code:
    #OfRecord = 1

    #2
    When sending an error, dsResponse.data is expected to be a String. In the case below, just combine the errorCode and errorMsg in the way you want it to be shown to the user.

    If you have special client-side handling in mind, the simplest thing is probably just to parse out the error code, although it is also possible to use dsResponse.setProperty() server-side and dsResponse.getAttribute() client-side in order to pass along extra information in a more structured way.

    Comment


      #3
      noted and thx your help

      Comment

      Working...
      X