PDA

View Full Version : Decode rest response on errors



vincentc
16 Apr 2014, 4:09 AM
Hello,

I meet a problem on Rest proxy to decode response. The aim is to pass additional information in response to better treat the error in extjs app.

We could take 409 http status code for example : http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10. As it is written : "The response body SHOULD include enough
information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem;"

Here is a success try to decode error message :


/**
* Decode response when there are errors on request too. It's useful to get
* error messages from server when sending an according HTTP error code as
* "409 conflict" for example.
*/
processResponse: function(success, operation, request, response, callback, scope){
var me = this,
result;


if (success !== true) {
try {
result = Ext.decode(response.responseText);


Ext.apply(operation, {
response: response,
responseJson: result
});
} catch(e) {
me.setException(operation, response);
me.fireEvent('exception', this, response, operation);
}
}


this.callParent(arguments);
}

Have you a better approach ?