PDA

View Full Version : How to Error message in store sync callback



Alexei Ptitchkin
29 Aug 2012, 7:22 AM
To handle success or fail store.sync() I use to pass sync options with callbacks.


var syncOptions = {controller:this,
record:record,
recordId:recordId,
dealerStore:dealerStore,
wnd:wnd,
success:this.lookupDealerSyncCallback,
failure:this.failureSyncCallback};
this.getDealersLookupStore().sync(syncOptions);

On server side I always write json response to client using:


this.getResponse().setContentType("application/json;charset=UTF-8");
this.getResponse().getWriter().write(json);


then if sync() succeed within call back I can access response text via batch.operations[0].response.responseText


lookupDealerSyncCallback:function (batch, syncOptions){
syncOptions.dealerStore.load();
syncOptions.wnd.close();


//batch.operations[0].response.responseText = "{"dealers":
// {"dealerCode":"BSDA","dealerName":"BUSINESS SOLUTIONS DIVISION,",
// "hasDefaultAllocation":"N","hasForecast":"Y","hasSellHand":"N",
// "hasQuota":"Y","createOn":"08/22/2012 13:29:09","createBy":"Eric Gu",
// "updateOn":"08/22/2012 13:29:09","updateBy":"Eric Gu",
// "ordinal":0,"id":283,"idx":0},"success": true }"

var responseObj = Ext.JSON.decode(batch.operations[0].response.responseText,true);
var newDealerId = responseObj.dealers.id;
syncOptions.record.setId(newDealerId);
syncOptions.controller.openDealerDetailWnd(null, syncOptions.record);
},

but if sync() fail batch.operations[0] does not have 'response' property and I don't have any message to show.


failureSyncCallback:function (batch, syncOptions){
syncOptions.dealerStore.load();
/*
* here batch.operations[0] does not have 'response' property
*/
},


How I can get error message in failure callback?

Thank you.

vietits
29 Aug 2012, 5:42 PM
See my answer for the same question here: http://www.sencha.com/forum/showthread.php?239873-store-sync-cannot-obtain-response-in-failure-listener...

Alexei Ptitchkin
29 Aug 2012, 6:23 PM
See my answer for the same question here: http://www.sencha.com/forum/showthread.php?239873-store-sync-cannot-obtain-response-in-failure-listener...

Thanks for response. :)
My point was: - Why I can NOT see response in batch.operations[0]?

As a way around I did "Message alert in store's exception listener" and silent failure recovery in "failureSyncCallback:function". But I really don't like to have such multistage error processing.