Announcement

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

    Callback executed even if WillHandleError is false

    SmartGWT 3.0p (2012-08-30)

    I'm calling fetchData from a datasource (RestDataSource) and a callback is defined.
    WillHandleError is set to false on the request.
    If the server returns XML with status set to -1, then the error message is displayed correctly... but the callback is called, which is not what we want.
    If I call fetchData from a listgrid connected to the same datasource, the error message is displayed correctly and the callback is not executed, like it is supposed to do.


    Here is the code of the datasource...

    Code:
    public class BaseDataSource extends RestDataSource {
    	    
    	protected BaseDataSource(String id) {
    		setID(id);
    		setDataProtocol(DSProtocol.POSTMESSAGE);
    		setDataURL("/RESTServlet/appserver");
    		
    		OperationBinding fetch = new OperationBinding();
    		fetch.setOperationType(DSOperationType.FETCH);
    		fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
    		OperationBinding add = new OperationBinding();
    		add.setOperationType(DSOperationType.ADD);
    		add.setDataProtocol(DSProtocol.POSTMESSAGE);
    		OperationBinding update = new OperationBinding();
    		update.setOperationType(DSOperationType.UPDATE);
    		update.setDataProtocol(DSProtocol.POSTMESSAGE);
    		OperationBinding remove = new OperationBinding();
    		remove.setOperationType(DSOperationType.REMOVE);
    		remove.setDataProtocol(DSProtocol.POSTMESSAGE);
    		
    		setOperationBindings(fetch, add, update, remove);
    	}
        
        private void setParams()
        {
    		String sessionId = Session.getInstance().getSessionId();
    		String userName = sessionId.equals("") ? Session.getInstance().getUserName() : "";
    		String password = sessionId.equals("") ? Session.getInstance().getPassword() : "";
    		String appServer = Session.getInstance().getAppServer();
    		String env = Session.getInstance().userInfo.getEnvironment();
    		
    		String session = userName + ":" + password + ":" + sessionId + ":" + appServer + ":" + env;
    		
    		String encSession = Base64.encode(session);
    			
    		final HashMap<String,String> map = new HashMap<String,String>();
    		map.put("session", encSession);
    		setDefaultParams(map);		
        }
        
        @Override
        public Object transformRequest(DSRequest request)
        {
        	request.setWillHandleError(false);
        	Object objRequest = super.transformRequest(request);
        	
        	setParams();
           	
        	return objRequest;
        }
    }
    Can someone help me find why this is not working correctly ?
    It should be easy to reproduce.

    I declare a datasource that extends the BaseDataSource.
    Code:
    public class TestDataSource extends BaseDataSource {
    	
        private static TestDataSource instance = new TestDataSource("test");
        
        public static TestDataSource getInstance() {
          	return instance;
        }
        
        private TestDataSource(String id) {
        	
        	super(id);
    
    	setDataURL("/RESTServlet/getTest");
    
    	DataSourceTextField field1 = new DataSourceTextField("field1", "field1");
        	field1.setCanSave(true);
        	field1.setCanEdit(true);
        	addField(field1);
        };
    }
    Then I just call it, and even if status of the response is -1, the callback is executed.

    Code:
    TestDataSource.getInstance().fetchData(crit, new DSCallback() {
    			
    	@Override
    	public void execute(DSResponse response, Object rawData, DSRequest request) {
    				
    		SC.warn(Integer.toString(response.getStatus()));
    	}
    });

    Here is the XML returned by the server.

    <response><status>-1</status><data>You are not authorized to use this module</data></response>


    Waiting for help...
    Last edited by jocelyndionne; 31 Aug 2012, 05:00. Reason: More details

    #2
    Did you ever discover why the callback is still called?

    Hi there

    SmartClient Version: 8.0/LGPL Development Only (built 2011-01-21)
    Browser: Chrome Version 27.0.1453.116 m

    I believe I am seeing the same behaviour. I don't include willHandleError in the dsRequestProperties. I have something like this:

    Code:
     
    
    myDatasource.fetchData(myCriteria, this.ID + '.callbackFunction(dsResponse, data, dsRequest)');
    
    callbackFunction: function (dsResponse, retData, dsRequest) {
    	// I don't want to do this check in every single callback
    	if (dsRsponse.status >= 0) {
    		// Do some stuff
    	}
    }
    My server code catches a problem sets the dsResponse status to -1, puts the error text in the data property and sends the response as a normal HTTP 200.

    SmartClient code then handles the error by showing an error box with the error message I sent. This indicates to me that SC recognises an error has occurred. I want this behaviour to continue.

    The problem I am having at this point is that the callback I specified in my fetchData is still called. I could be mistaken but the DSCallback documentation is a little confusing, it says:

    "Note that if the request encounters a low-level error (such as 500 server error), by default the callback will not be fired, instead, DataSource.handleError() is called to invoke the default system-wide error handling. Set willHandleError:true to have your callback invoked regardless of whether there are errors, however, make sure your callback properly handles malformed responses when DSResponse.status is non-zero."

    So does this mean I should make my server send a HTTP 500 because HTTP 200 with -1 status isn't a low-level error?

    From the Developer Console:

    Code:
    // From RPCRequest box
     
    ...
       }, 
        "willHandleError":false, 
        "serverOutputAsString":true, 
        "data":null
    ...
    
    // From Response box
    {"response":{"endRow":0,"totalRows":0,"status":-1,"startRow":0,"data":"My error"}}
    Regards,
    Alex

    Comment

    Working...
    X