Results 1 to 5 of 5

Thread: Correct way to stop record delete from store

  1. #1
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    261
    Answers
    6

    Default Correct way to stop record delete from store

    I have a simple store with rest proxy:
    Code:
    Ext.define('MyApp.Store.Holidays', {
        extend: "Sch.data.EventStore",
        autoLoad: true,
        autoSync: true,
        batch: false,
        proxy: {
            type: 'rest',
            pageParam: false, //to remove param "page"
            startParam: false, //to remove param "start"
            limitParam: false, //to remove param "limit"
            noCache: false, //to remove param "_dc"
            url: 'api/Holidays',
            reader: {
                type: 'json',
                root: 'data'
            },
            writer: {
                type: 'json'
                //,allowSingle:false
            },
            listeners: {
                exception: function (store, response, op) {
                    try {
                        var data = Ext.decode(response.responseText);
                        MyApp.getApplication().showError("Server error", data.Message);
                        store.add(store.getRemovedRecords());
                    }
                    catch (ex) {
                        MyApp.getApplication().showError("Error", "Error#2");
                    }
                }, scope: this
            }
        },
        model: 'MyApp.Model.Holiday'
    });
    On server side I validate every request and I response with:
    Code:
    Request URL:http://localhost:1500/api/Holidays/168
    Request Method:DELETE
    Status Code:200 OK
    or with:
    Code:
    Request URL:http://localhost:1500/api/Holidays/212
    Request Method:DELETE
    Status Code:409 Conflict
    and response:
    Code:
    {"Message":"Data modified, please reload Your plan.","success":false,"Code":4,"Status":409}

    What I have right now is error message shown to user when I get exception from server.
    What I want to avoid is removal of that record from store when there is exception.
    So my question is how should my server response look to correctly display error message to user and avoid that record removal.

    Are there any samples of correct responses, both success and error (one when everything is fine and record is removed correctly and second when record can't be removed-validation failed)

    I know that exception listener should be used for server exceptions handling, but I don't want to use response status 200 for something that isn't correct (in my case validation)

  2. #2
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    261
    Answers
    6

    Default

    Sorry to bump this, but I really can't find anything about proper rest responses.
    How should the success message look, how fail message.
    Should server in all cases return OK (200) or should it return different responses for different operations?
    How to handle server responses?

    Like in scenario:
    User requested GET operation- how should response look if everything is OK, how when for example verification failed (I just wast to send some error) and when something on server crashed?

    User does PUT operation? What should response look (header should be 200) what about errors? If I want to update model is some criteria are correct? How to inform store that model isn't updated and how to show proper message to user?

    Same with DELETE-how to inform user that server didn't validate model (someone modified it and it can't be deleted) and how to rollback delete? I don't know what my server should return to stop model from being deleted.

  3. #3
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Answers
    4

    Default

    One way is to disable removing records on store level and define remove in proxy api of model.
    This allows you to pass a success/failure callback methods to model.save() where you could define, based on server response, whether to remove the record from the store or not

  4. #4
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    261
    Answers
    6

    Default

    It is better to have proxy in store is I use store for grid or scheduler.
    The thing I don't know is what should I return from server to stop that removal from happening.

  5. #5
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Answers
    4

    Default

    Whether it is better to have proxy in store or model depends what are trying to achieve.
    Both in save() method of model or sync() method of store can have success and failure functions defined.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •