1. #1
    Sencha User
    Join Date
    Apr 2010
    Posts
    79
    Vote Rating
    6
    Answers
    3
    HriBB is on a distinguished road

      0  

    Default Unanswered: How to reject record on Ext.direct server exception

    Unanswered: How to reject record on Ext.direct server exception


    When you save a record with Ext.direct proxy and a server exception occurs, how can I reject the record? Callback function is not called, and there is no exception function on Ext.data.Operation.

    I did find an ugly workaround, but there's gotta be a better way to do this ... or not???

    Code:
    // record with a fully working Ext.direct proxy
    var record;
    
    // create exception handler
    var exceptionFn = Ext.bind(function(record) {
         // reject record
         record.reject();
         // remove listener if exception occured
         Ext.direct.Manager.un('exception', exceptionFn);
    }, this, [record]);
    
    // listen to Ext.direct exceptions
    Ext.direct.Manager.on('exception', exceptionFn);
    
    // save record
    record.save({
         callback: function(records, operation) {
             // this never gets called if server exception occurs
             // remove listener if exception did not occur
             Ext.direct.Manager.un('exception', exceptionFn);
         }
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    898
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Couple issues I see. Using Ext.direct means you may have multiple requests bundled into a single request so if one fails then the others fail but that doesn't mean the record saving wasn't successful.

    You shouldn't allow the direct router to fire anything that wouldn't give a successful JSON reading meaning if there was a server side error (like a PHP error). Each request needs to have success true/false to tell each request is successful or not.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread