Extjs store error handling

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

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

I get a request exception, even if the server returns an HTTP 200 Response!

To get the 'remote' error, I need to create an object with the root property

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

... but I do not want this. Is there any way to change this behavior?

In addition, when I insert a record into the repository, it is automatically added to the linked grid, but if an error occurs, it remains there, so I need to reboot the repository with every error. Is there a better way to do this?

+6
json error-handling extjs jsonstore
source share
3 answers

Finally, I found out that if I send back empty data, it will work as expected. Therefore, I do not need to send any fictitious data, my answer to the server:

 ({ "success": false, "message": "some text", "data": {} }) 
+4
source share

You must catch one of two Store events:

  • loadexception (deprecated)
  • 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 can also simply use the Success and Failure events from the repository to take actions based on the success flag.

+10
source share

when success is a false operation, it does not have the property of an answer. This thread explains it very clearly!

http://www.sencha.com/forum/showthread.php?196013-access-operation.response-when-success-false

Example:

 Ext.define("SC.store.SegurosCancelacionStore", { extend: "Ext.data.Store", model: "SC.model.PersonaSeguro", proxy: { timeout: 90000, actionMethods: { read : 'POST' }, type: "ajax", url: "../SegurosFinsolCancelacionServlet", reader: { type: "json", root: "seguros", messageProperty : 'msjError' //without this, it doesn't work } }, autoLoad: false }); 

Implementation:

 storeSegurosCancelacion.load({ params: { 'sucursal':sucursal, 'persona': persona }, callback:function(records, operation, success){ msg.hide(); if(success == true){ if(records.length == 0){ Ext.Msg.alert('Resultado', 'No se ha encontrado información'); } } if(success == false){ try{ Ext.Msg.alert('Error', operation.getError()); // way more elegant than ussing rawData etc ... }catch(e){ Ext.Msg.alert('Error', 'Error inesperado en el servidor.'); } } } }); 

Regards @ Code4jhon

0
source share

All Articles