PDA

View Full Version : How Retrieve ResponseText following store.load() failure?



simonr25
21 May 2013, 7:55 AM
Hello

Please can you explain how I can obtain the responseText following a failed store.load() call.
I require to obtain the reason text from the response below.
I assume I need to use a callback - but I can't determine the exact solution. Is there a
separate success and failure callback?
something similar to below:



var st = Ext.create("App.store.Companys");

st.load({callback: function(records,operation,success) {
var obj = Ext.decode(operation.response.responseText);
console.log("succ: "+success);
console.log("reason: "+obj.errors.reason);
console.log("records: "+records);
}});


controller:
@RequestMapping(value = "/res.action", method = RequestMethod.GET)
public @ResponseBody String res(HttpServletRequest request, HttpServletResponse response) {

String str = "{\"success\":false, \"errors\": { \"reason\": \"Session Expired.\" }}";
return str;

}

friend
21 May 2013, 8:54 AM
operation.getError() will typically return a JSON object like so:



{
status: 500,
statusText: 'Internal Server Error'
}

simonr25
22 May 2013, 1:38 AM
Thank you for your reply.
I am now able to obtain the response status (by using operation.getError().status).
However I am unable to obtain the text.

I altered the return string to:
{"success":false, "message": "Session Expired."}
and set messageProperty to 'message' in the store ajax proxy reader
I set response status to a customised value, e.g. 499

I have tried:
operation.getError().statusText
operation.getError().message
operation.getError().responseText

all are undefined?

friend
22 May 2013, 4:43 AM
When a server-side failure occurs, the operation object can only capture the HTTP status information about the failure. In other words, it's a server failure, not a 'logical' failure that you are controlling server-side. If your session is expired, you're never going to make it to your /res.action URL Mapping. The web container is going to blow you off with an appropriate HTTP response.

simonr25
22 May 2013, 6:30 AM
Thank you for your reply. It is much appreciated.

The string being returned will not normally contain "session expired" but another error message
giving the client user information on why their request failed. The error message may appear in
e.g. an alert or a text field.

If the operation object can only capture the HTTP status information about the failure, then I
can return the status and map it to text to display to the user.

I was attempting to return text containing error information which could be extracted and displayed
to the user.

From testing, if the session has expired, the action in the mapping is invoked. However the session
is invalid.

kind regrds,
Simon