Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs store error handling

I am trying to handle an exception in an Ext.data.Store instance when creating a new Ext.data.Record. When the server responds with the following json:

{"success": false, "message": "some text"}

I get an exception of type 'request', even though the server returns an HTTP 200 Response!

To get a 'remote' error I have to create an object with the root property

({
    "success": false,
    "message": "some text",
    "data": {
        "PositionId": "00000000-0000-0000-0000-000000000000",
        "Name": "123"
    }
})

...but I don't want this. Is there any way to change this behaviour?

Also, when I insert a record in the store, it is automatically added to the associated grid, but if an error occurs it remains there, so I need to reload store on every error. Is there any better way to do this?

like image 922
kalan Avatar asked Feb 28 '11 11:02

kalan


1 Answers

You should catch one of the two Store events:

  1. loadexception (deprecated)
  2. exception

For example you could:

// make the store
var myStore = new Ext.data.Store({...});
// catch loading exceptions
myStore.on('exception',function( store, records, options ){
    // do something about the record exception
},this);
// load store
myStore.load();

You could also just use the success and failure events from the store to take action based on the success flag.

like image 50
Joseph Lust Avatar answered Sep 19 '22 17:09

Joseph Lust