1. #1
    Sencha User
    Join Date
    Mar 2008
    Posts
    53
    Vote Rating
    2
    Answers
    2
    manilodisan is on a distinguished road

      0  

    Default Answered: Tree menu handle failure calls on store

    I have a simple tree menu defined with a store attached. The store calls an url for the response containing the items it has. If the user is not logged in the servers responds:
    Code:
    {"message": "Invalid permissions", "data": {}, "success": false}
    My question is: how do I handle this response to catch it in a failure type method as a callback probably and show the user that error message or maybe redirect him to the login page.

    My tree is as follows:

    Code:
    Ext.define('AP.view.layout.MenuTree' ,{
    	alias : 'widget.mainMenuTree',
    	extend: 'Ext.tree.Panel',
    	border: false,
    	useArrows: true,
    	rootVisible: false,
    	initComponent: function(){
    		Ext.apply(this, {
    			viewConfig: {
    				getRowClass: function(record) {
    					if (!record.get('leaf')) {
    						return 'group ';
    					}
    					return record.get('cls');
    				}
    			},
    			store: Ext.create('Ext.data.TreeStore', {
    				model: 'Menu',
    				proxy: {
    					type: 'rest',
    			                url : AP_ROOT_URL + 'menu/',
    			                reader: {
    			                        type: 'json',
    			                        successProperty: 'success'
    			                }
    				}
    			})
    		});
    		this.callParent();
    	}
    })
    I see it has a successProperty but how do I catch the failure message?

  2. You should be able to inspect everything about the server response in that callback.

    If you'd prefer to grab the data in a different place with less work to get to the response, you can add a listener to your store's proxy. I'm guessing you might be using an Ajax proxy:

    http://docs.sencha.com/ext-js/4-0/#!...vent-exception

  3. #2
    Sencha - Tools Team arthurakay's Avatar
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,425
    Vote Rating
    64
    Answers
    65
    arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice

      0  

    Default

    Add an event listener to your TreeStore!

    http://docs.sencha.com/ext-js/4-0/#!...ore-event-load

  4. #3
    Sencha User
    Join Date
    Mar 2008
    Posts
    53
    Vote Rating
    2
    Answers
    2
    manilodisan is on a distinguished road

      0  

    Default

    Yeah I can get the success property by that callback but no way to access any other data being sent by the server. Am I wrong?

  5. #4
    Sencha - Tools Team arthurakay's Avatar
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,425
    Vote Rating
    64
    Answers
    65
    arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice

      0  

    Default

    You should be able to inspect everything about the server response in that callback.

    If you'd prefer to grab the data in a different place with less work to get to the response, you can add a listener to your store's proxy. I'm guessing you might be using an Ajax proxy:

    http://docs.sencha.com/ext-js/4-0/#!...vent-exception

Thread Participants: 1