1. #1
    Sencha User aatiis's Avatar
    Join Date
    Nov 2011
    Location
    Bajmok, Serbia
    Posts
    60
    Answers
    3
    Vote Rating
    2
    aatiis is on a distinguished road

      0  

    Default Answered: REST proxy server response when creating

    Answered: REST proxy server response when creating


    I'm trying to create a new model on the server, like this:

    Code:
    model = Ext.create("MyApp.model.MyModel", {
        some: "data"
    });
    model.save({
        callback: function (record, operation) {
            // How to get server response here?
            // This works sometimes but not always:
            response = Ext.decode(operation.getResponse().responseText);
            Ext.Logger.info("Model created, id is " + response.records[0].id);
            model.setId(response.records[0].id);
        }
    })
    Is there a sane way of accessing the result that the server sends from within the callbacks provided to model.save()?

  2. Solution seems to be to subscribe to the 'exception' event. Unfortunately the it doesn't seem to be possible to reference the response from the exception event handler, so it needs to be re-read, using proxy.getReader().read(response).getMessage() (and configure messageParam on the reader accordingly).

    An easier solution is to defune a custom reader, which is what we did.

  3. #2
    Sencha User aatiis's Avatar
    Join Date
    Nov 2011
    Location
    Bajmok, Serbia
    Posts
    60
    Answers
    3
    Vote Rating
    2
    aatiis is on a distinguished road

      0  

    Default


    A little digging around revealed that the callback is fired from

    Code:
    Ext.data.proxy.Server.processResponse()
    …which does not set the "response" as a parameter when calling any callbacks.

    It does however set the parameter when calling the "exception" event, so I guess the answer is to sign up to the "exception" event rather than using callbacks, to handle failures.

    This still doesn't solve the problem if there are no exceptions, i.e. we want to get the ID returned from the server.

  4. #3
    Sencha User aatiis's Avatar
    Join Date
    Nov 2011
    Location
    Bajmok, Serbia
    Posts
    60
    Answers
    3
    Vote Rating
    2
    aatiis is on a distinguished road

      0  

    Default Solution

    Solution


    Solution seems to be to subscribe to the 'exception' event. Unfortunately the it doesn't seem to be possible to reference the response from the exception event handler, so it needs to be re-read, using proxy.getReader().read(response).getMessage() (and configure messageParam on the reader accordingly).

    An easier solution is to defune a custom reader, which is what we did.

  5. #4
    Sencha User
    Join Date
    Sep 2012
    Location
    Buenos Aires
    Posts
    17
    Vote Rating
    0
    nguerin is on a distinguished road

      0  

    Default


    Yes. The success and failure callbacks are called with two arguments--the new model and operation. The server's response can be found in the operation object:

    Code:
    makeRequest: function (model, callbacks) {
    Code:
            var me = this;
            model.save({
                success: function(newModel, operation) {
                    console.log("tryModelHandling callback");
                    try {
                            var loginResult = me.getResponseData(operation.getResponse());
                            Cortana.manager.SessionHandler.setToken(loginResult.sessionGuid);
                            Cortana.manager.SessionHandler.setUserAccountGuid(loginResult.userAccountGuid);
                            Cortana.manager.SessionHandler.setEmployeeGuid(loginResult.employeeGuid);
    // call the callback function passing in the result from the server
                            callbacks.success.call(callbacks.scope, loginResult);
                    } catch (e) {
                        window.console.log('Error in Cortana.manager.Login#makeRequest: ' + e.toString());
                    }
                },
                failure: function (newModel, operation) {
                    var loginResult = me.getResponseData(operation.getResponse());
                    callbacks.failure.call(callbacks.scope, loginResult);
                } 
            });

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi