Results 1 to 3 of 3

Thread: [ExtJs 3.0.2] Ext.data.Store exception is type response instead of type remote

  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2009
    Posts
    96

    Default [ExtJs 3.0.2] Ext.data.Store exception is type response instead of type remote

    The code for the exception handler:
    Code:
    onException:function(proxy,type,action,request,response,arg){
        if(type == 'response') {
            switch(action) {
                case 'update':
                    this.getById(request.params.id).reject();
                    this.queue.remove(request.params.id);
                break;
                case 'create':
                    this.remove(this.getById(request.params.id));
                    this.queue.remove(request.params.id);
                break;
            }
            Ext.Msg.show({
                title:'Invalid response!',
                icon: Ext.MessageBox.WARNING,
                msg:'The server returned an invalid response for the requested action.',
                buttons:Ext.Msg.OK
            });
        }
        else if(type == 'remote'){
            switch(action) {
                case 'update':
                    this.getById(request.params.id).reject();
                    this.queue.remove(request.params.id);
                    switch (response.raw.type) {
                        case 'server':
                            Ext.Msg.show({
                                title:'Server error!',
                                icon: Ext.MessageBox.WARNING,
                                msg:response.raw.errors.update,
                                buttons:Ext.Msg.OK
                            });
                        break;
                        case 'crud':
                             Ext.Msg.show({
                                title:'Crud error!',
                                icon: Ext.MessageBox.WARNING,
                                msg:response.raw.errors.crud,
                                buttons:Ext.Msg.OK
                            });
                        break;
                        case 'validation':
                              Ext.Msg.show({
                                title:'Validation error!',
                                icon: Ext.MessageBox.WARNING,
                                msg:response.raw.errors.validation,
                                buttons:Ext.Msg.OK
                            });
                        break;
                    }
                break;
            }
        }
    }
    Exception handler parameters with relevant values:

    Code:
    proxy:{proxy reference object}
    type:response
    action:create
    request:{request object}
    response:{response object}
    arg: Ext.data.JsonReader: root-undefined-response arg=data message=root-undefined-response
    The response responseText property:

    Code:
    {"success":false,"type":"Validation","errors":[{"id":"Language","msg":"Object reference not set to an instance of an object."},{"id":"LocaleId","msg":"LocaleId and LanguageId must be valid!"}]}
    The problem is that even though the responseText is valid json, the reponse type is evaluated as being of response type (instead of remote).

    Judging by what the last parameter dictates i'd say that the problem in this case is that the store associated reader cannot interpret the reponseText property of the response object.

    DataProxy exception event docs say:

    type : String
    The value of this parameter will be either 'response' or 'remote'.
    • 'response' :
      An invalid response from the server was returned: either 404, 500 or the response meta-data does not match that defined in the DataReader (e.g.: root, idProperty, successProperty).
    • 'remote' :
      A valid response was returned from the server having successProperty === false. This response might contain an error-message sent from the server. For example, the user may have failed authentication/authorization or a database validation error occurred.
    There is no info there to state that the responseText property on write should be interpretable by the stores associated reader. It also makes no sense for it to be. When using CRUD's, reponseTexts vary depending on the action that triggered them. Reader interpretation is only necessary when the action is load and the store expects the returned data to be an array of records ... (at least) in my case, the create and update methods return a message of type:
    Code:
    {"success":true/false, "id"(success == true):recordId, "msg"(success == false):myMsg}
    This cannot be interpreted by the exception handler. The exception handler expects a responseText like:
    Code:
    {"success":true/false, "totalRecords":recordNumber, "data":[Array of records]}
    Also, why does success false trigger the exception event? I think this modification is fresh to Ext 3.x, in 2.x success false was evaluated on outside of the exception category. Exception was only firing on server status != 200 or invalid response text...to me at least it makes more sense this way (leave exception as a handler for invalid server reponse)

    Thanks!

  2. #2
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664
    Answers
    512

    Default

    I can say little about design decisions of the devel-team. Maybe you could mail to [email protected] with link to this post. Or file it as a bug report or feature request.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


  3. #3
    Ext JS Premium Member
    Join Date
    Mar 2009
    Posts
    96

    Default

    Thanks for the reply, i'm posting this in the bugs section .

Posting Permissions

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