PDA

View Full Version : Detect reason why Ext.data.JsonP.request failed



Dumas
1 Aug 2012, 9:16 AM
Is there any way to detect why a Ext.data.JsonP.request failed?

Currently I get redirected to the login page, so I would like to do something like

Ext.data.JsonP.request({ ...
url: url
failure: function(response, opts) {
if(response.url !== url) {
Ext.Msg.alert('Please login first: <a href="'+response.url+'>Login here</a>');
} else {
this.showFailure();
}
},
});

But the response if just a string "error"

Any tips?

thanks
Roland

scottmartin
1 Aug 2012, 10:06 AM
Not much information to go on ..

-Do you get a return at all, if you enter url manually, do you get return
-Is the return formatted properly, do you have control of the return?

Scott.

Dumas
1 Aug 2012, 3:54 PM
Hello,

Normally I request data it everything works fine.

Just in the case that my session expired, I don't get any data, the server redirects me to users/login.
When I then do console.info(arguments) inside the failure callback I get ["error"]. So I wondered if ExtJS can give me more information on what went wrong so I can distinguish the session-expired error from other errors.

thanks
Roland

scottmartin
1 Aug 2012, 4:30 PM
You can check your error codes, place exception listeners ..



proxy : {
listeners : {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}


In your callback, if you had a ajax failure, you would get a failure vs a server response error would return success: false, error message



Ext.Ajax.request({
success:function (xhr) {
var response = Ext.decode(xhr.responseText);
if (response.success === true) {
} else { // your error response from server}
},
failure:function () {
alert('AJAX FAILURE: no response from server');
}
});


Scott.

Dumas
10 Aug 2012, 4:41 PM
Hello Scott,


I was wondering if I could get the specific error code (like a 403 for a redirect), because in this special case I would like to show the user a login screen.


thanks
Roland

luisparada
11 Aug 2012, 8:28 AM
I think you should check your backend application and system logs too, I always manage exceptions in the backend and only connection exceptions in the front end, so, double check your application and try to print out your errors, if is nothing there, check the system logs.

skirtle
11 Aug 2012, 9:41 AM
One of the big weaknesses of using JsonP is its poor error handling. This isn't a framework deficiency, the underlying transport mechanism just doesn't allow for it. There's also vastly different support across browsers, IE in particular.

If you take a look at the source of Ext.util.JsonP you can see how the error handling works. It relies on the error event firing on the script tag. All ExtJS knows is that an error occurred, it doesn't know any more than that.

From what you've described it sounds like your server's approach to handling session timeouts is inappropriate. For a JsonP request it should return the session error in JsonP. That way you have the opportunity to read the response and react accordingly.

Dumas
11 Aug 2012, 11:07 AM
Hello,

thanks for the explanation. I will work on a different approach :)

best regards
Roland