PDA

View Full Version : Ext.data.proxy.Rest exception event always gives empty response.responseText



rso@catalogicsoftware.com
9 Feb 2016, 3:26 PM
Ext.data.proxy.Rest exception event always gives empty response.responseText
We are using Ext.data.proxy.Rest and listen to the "exception" event in attempt to handle non-200 HTTP code return from our RESTful API. The event triggered but the response field that is included in the event function never captures the response body that the RESTful API returns. I have even looked into overriding the processResponse method but I am still not able to get a hold of the response. The response is in JSON format.

How do I capture the message? Is there also a way to capture the return code such as 404, 500, or 503?

Thanks a lot in advance,
Ronald

chamacs
10 Feb 2016, 7:35 AM
The event you need to listen to is "requestexception". I don't know what version you are using, so I don't know where/when a change was made to where to listen to that event.


For example, when we used ext 4.1.1, we did it this way:

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


// Handle redirect for requests when there is a timeout of some sort...
Ext.data.Connection.on('requestcomplete', this.onRequestComplete);

We then jumped directly to 5.x, so we had to chnage it to this:

Ext.mixin.Observable.observe(Ext.Ajax);
Ext.Ajax.on({
// For Handling Global Exception Errors 500, 404, 403, ...
requestexception : this.onRequestException,


// Handle redirect for requests when there is a timeout of some sort...
requestcomplete : this.onRequestComplete
});

What I don't know is if the change happened in some later version of ext 4.x.


See the API for the function signature. The response.status gives you the HTTP code.


Hope this helps.

rso@catalogicsoftware.com
12 Feb 2016, 9:53 AM
Thanks for your help. I have tried to listen to the requestexception event and I can see the error code when I do POST. However, using GET and the response does not come back with info that contains 503 error code. It just shows 0. I have tried both APIs via POSTMAN and they returned correctly. The responses were identical except that the POST call returns a 400 (Bad request) but GET call returns 503 (Server unavailable). The requestexception event was thrown in both cases. The response field contains everything I needed for the HTTP400 case, but the 503 case always return statusCode=0.