PDA

View Full Version : store/proxy: catch server side errors



mbalsam
28 Jul 2011, 11:44 PM
Hello everybody,

is it possible to check the http response status for requests sent via a store/proxy. My server sends a 401 when the user authentication fails and in that case I want the login mask to re-appear. Chrome recognizes the 401 but my application does not. I don't know where to check for the response status as neither proxy nor store allow a failure callback for their load/read methods. Any Ideas?

mbalsam
29 Jul 2011, 3:08 AM
No One? Btw. I am using a ScriptTagProxy if that makes any difference here.

The Connection/Ajax classes provide a requestexception event that can be handled and where the response status can be extracted? Why ain't there such an event for proxies/stores? Honestly, are proxies supposed not to receive an error status? The ScriptTagProxy's exception event is no alternative as it only and only fires when the connection times out. That doesn't suffice for my purposes.

EDIT: On another note why does the exception event for ScriptTagProxy contain the request where the one for AjaxProxy contains the response?

jjerome
29 Jul 2011, 4:41 AM
See if this code helps you out. I created this example of an Ajax call.
Also another version of an xmlhttp proxy below:




Ext.Ajax.request({
url: 'urlhere',
scope: this,
success: function(response){
alert(response.responseText);
}
failure: function(response){
if(response.status == 500){
Ext.Msg.alert('',"User/Password incorrect. Please try again.", Ext. emptyFn);
}
else{
Ext.Msg.alert('', "Server could not be reached. Please try again later.", Ext.emptyFn);
}
}
});




var xmlhttp;
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
//do something here
}
if(xmlhttp.readyState==4 && xmlhttp.status == 500){
//do something here
}
};
xmlhttp.open("GET","...",true);
xmlhttp.send();

mbalsam
29 Jul 2011, 5:24 AM
Thanks for your help. Your code will probably not help me though. I need to use a ScriptTagProxy and there is neither a failure callback nor the option to inspect the response.