View Full Version : JsonP proxy exception handling

9 Oct 2013, 12:22 PM
Hi guys,

So I have a little question on an issue I can't seem to figure out.

I created a login store using with a jsonp proxy and a json reader. This store sends credentials to the server and the server replies back with basic user profile information embbeded in Json format. So far, so good.

My issue is with the exception handling. When we try to use through this proxy with, let's say, wrong credentials, we've made our server send back an HTTP code of 401 (to force the proxy to throw an exception). However, we also pass a json object alongside this response with a details on the issue. This response doesn't seem to be parsed by the reader (fair enough, there was an exception) but there's no raw response to read or anything that could let me access this response body.

Code sample:

proxy: {
type: 'jsonp',
timeout: 2000,
reader: {
type: 'json'
listeners: {
exception: function(proxy, response, operation, eOpts) {
console.log("An exception occurred");
console.log(response); //always null

Response header:

HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/
Date: Wed, 09 Oct 2013 20:05:34 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/javascript
Connection: Close

Response body:
"token": "",
"userProfile": null,
"returnCode": 400,
"messages": [
"Authentication failed: Please verify the credentials."
"processedDateTime": "2013-10-09T16:05:34.9788163-04:00"

My question(s):

Is there a way to access this response body?
Is it a limitation of the JsonP proxy? I've seen people being pretty successful with Ajax proxies.


9 Oct 2013, 3:50 PM
Can't you use the exception event from the store?

exception (http://www.sencha.com/forum/#!/api/Ext.data.proxy.Server-event-exception)( this, response, operation, eOpts )
Fires when the server returns an exception

10 Oct 2013, 5:50 AM
I tried that but unfortunately had the same issue.

But the good news is, I finally figured out the problem. The response ContentType, whenever the status code isn't 200, should be text/html.

text/javascript or application/json is only working when the response is a success. (I was returning text/javascript no matter what kind of code I was sending).

I hope this helped somebody.

Thanks for the reply anyways ;)