PDA

View Full Version : Need to handle exception or failure on the loadPage method



andresdavidortiz
25 Aug 2014, 6:13 AM
I use that function to load pages from the web server, the thing is: sometimes the query is so big that request time gets out. And because I receive the answer from server only when it's ok, the callback function doesn't trigger. Anyway I need to handle that exception 500, that is to say, an answer with no return.

chamacs
25 Aug 2014, 6:10 PM
I assume you're using/setting a timeout on your AjaxProxy:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.proxy.Ajax-cfg-timeout

You're probably looking for something like this. Somehow you'll initialize this on App start up:


Ext.util.Observable.observe(Ext.data.Connection);
// For Handling Global Exception Errors 500, 404, 403, ...
Ext.data.Connection.on('requestexception', this.onRequestException);


See the API for the event parameters:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Connection-event-requestexception

The response parameter has a 'timedout' attribute to know if the AJAX request timedout on the ExtJS side.

Hope this helps.

andresdavidortiz
26 Aug 2014, 8:06 AM
Thanks chamacs, I've already got a solution: Before calling the loadPage function on the go, I add a exception event on the Proxy.

Proxy = Mystore.getProxy();
Proxy.clearListeners();
Proxy.on("exception",function (proxy,request,operation,eOpts)
{
alert("Message for handling the situation");
},this);


Mystore.loadPage(numberOfThePage,{params},callback:function(records, operation, success)
{
//MyCode
}

Anyway you code and suggestion is very interesting and it will be helpful on other things I'm doing. Thanks a lot.

chamacs
26 Aug 2014, 10:35 AM
Thanks chamacs, I've already got a solution: Before calling the loadPage function on the go, I add a exception event on the Proxy.

Proxy = Mystore.getProxy();
Proxy.clearListeners();
Proxy.on("exception",function (proxy,request,operation,eOpts)
{
alert("Message for handling the situation");
},this);




Mystore.loadPage(numberOfThePage,{params},callback:function(records, operation, success)
{
//MyCode
}


Anyway you code and suggestion is very interesting and it will be helpful on other things I'm doing. Thanks a lot.

Cool. Just a side note on the example you posted: There is a way to add a 'single use' listener so you wouldn't have to call clearListeners() all the time:



Proxy = Mystore.getProxy();
Proxy.on("exception",function (proxy,request,operation,eOpts)
{
alert("Message for handling the situation");
},this, {single : true});


This would be useful when your 'observable object' has other listeners you want to maintain. Again, hope this helps.

andresdavidortiz
26 Aug 2014, 10:59 AM
Cool. Just a side note on the example you posted: There is a way to add a 'single use' listener so you wouldn't have to call clearListeners() all the time:



Proxy = Mystore.getProxy();
Proxy.on("exception",function (proxy,request,operation,eOpts)
{
alert("Message for handling the situation");
},this, {single : true});


This would be useful when your 'observable object' has other listeners you want to maintain. Again, hope this helps.

This is Beautiful, I didn't know that. Thanks