Q:

Sencha extjs model.erase removes model even when server error

When calling model.erase({failure..., success...}) the model is removed even when the server responds with a HTTP StatusCode 500. The failure listener is triggered correctly but i would expect that model is not destroyed then. I can see that it is destroyed because it gets removed from the store.
var rec = store.getAt(index);
rec.erase({
     success:function(record, operation){
        // Do something to notify user knows
     }
     failure:function(record, operation){
        // correctly triggered when HTTP = 40x or 50x
        // Would expect that record is still in store. Why not?
        // Of course i could add it again to store with store.add(record) but is that the prefered way?
     }
});

I am using an AJAX proxy in Extjs 6.0

A:

The erase isn't really relevant here. Calling erase calls the model drop method, which marks it as pending deletion and removes it from any stores. Just because the server failed to delete it from the server doesn't necessarily mean you want it back in the store, it's still just pending deletion.

A:

Yes, the erase method removes the record from the store right away, without waiting for the server's response. The "hacky" way to handles you scenario will be:

set the record's dropped property to true;
save the record using the save method (it will generate a delete request but will keep the record in the store);
remove the record from the store on success, reset the dropped property to false of failure.
var record = store.getAt(index);
record.dropped = true;
record.save({
    success: function() {
        store.remove(record);
        // do something to notify the user
    }
    failure: function() {
        record.dropped = false;
    }
});

