View Full Version : failure handler in REST Proxy destroy() not responding properly

25 Feb 2014, 9:57 AM
Ok now this is definitely a weird one for me...
I'm using a standard REST Proxy with a store and am calling a destroy() to delete a record from the server.
There are times when the server wants to return a failure (for example if the record is locked for some reason and can't be deleted as an example). But my failure handler doesn't seem to receive the response message from the server before being called!

Here's my (VERY Limited) sample code for the destroy() method:

scope: this,
success: function(response, options) {
debugger; /* BP1 */
failure: function(response, options) {
debugger; /* BP2 */
callback: function( options, success, response) {
debugger; /* BP3 */

And here's the PHP code that gets called when the destroy() is called:

$json["success"] = true;
$json["description"] = "\"$name\"";
$json["msg"] = "Template Deleted.";
$json["success"] = false; // needed to display the error message
$json["description"] = "Template Delete Failed. $frameworkErr";
$json["msg"] = "Template Delete Failed. $frameworkErr";

Note that if the $frameworkErr is not null a success:false is being returned to the JS function, along with a msg.
The sequence of operations can be seen in the attached screenshots:
BP1-Success shows the results of a successful delete operation in the success handler along with the response object, although note that the "msg" element is blank even though the PHP code says it should contain "Template Deleted" (and the model does include a msg element). After the success method the callback method is called properly.48044

Now, if a failure in deleting the record occurs, the PHP code returns a success value of false, which "properly" causes the "failure" method to be called, but we can see that the response object does not contain a msg either, though the success parameter of the options object is properly set to "false"


Even stranger is that looking at the network tab in chrome shows that there's no response message yet received!


But, when the callback is triggered there's no response object (undefined below)


And upon completion of the callback we see that there is, finally, a response message showing the msg and a success of false.


So, long story short, what am I doing wrong that I can't seem to properly handle failure condition in a destroy method? And searching through the forums hasn't given me any clue to what I'm doing wrong. Why is the failure method being launched while the response from the server is still "pending" (according to chrome)?

Thanks in advance
Signed "Frustrated"

3 Mar 2014, 8:21 AM
I have this test:

Ext.define('MyModel', {
extend : 'Ext.data.Model',

fields : ['foo'],

proxy : {
type : 'rest',
url : '/data'

var record = new MyModel({
id : 1,
foo : 'bar'

failure : function() {

and it hits the failure for me when returning this json:

"success" : false,
"msg" : "No good"