PDA

View Full Version : store sync cannot obtain response in failure listener...



maneljn
28 Aug 2012, 10:57 AM
Ext. 4.1.1 RC2

I work with store.sync() method and in case of "destroy" action failure my php side returns success false and a message for user explaining why he cannot delete.



....
$respuesta['success'] = false;
$respuesta['errorNum'] = 0;
$respuesta['errorMsg'] = addslashes(dgettext("esicontactos","Esta dirección está vinculada a otras tablas. No se puede borrar."));
$respuesta['message'] = $respuesta['errorMsg'];
echo json_encode($respuesta);
return;


In javascript side:
this line works well in case of callback and succes, but response does not exists in case of failure.
console.log(batch.operations[0].response.result);



//
// Actualizar direcciones (Borradas, nuevas y modificadas)
//
storeDirecciones.sync({
// operaciones crud finalizadas
callback: function(batch, options) {
console.log("callback");
console.log(batch.operations[0]);
console.log(batch.operations[0].request.action);
console.log(batch.operations[0].response.result);
},
// operaciones crud todas correctas
success: function(batch, options) {
console.log("success");
console.log(batch.operations[0]);
console.log(batch.operations[0].request.action);
console.log(batch.operations[0].response.result);
},
// Alguna operacion crud con fallos
failure: function(batch, options) {
console.log("failure");
console.log(batch.operations[0]);
console.log(batch.operations[0].request.action);
console.log(batch.operations[0].response.result);
}
});

vietits
28 Aug 2012, 4:23 PM
In case of failure, you should use <operation>.getError() to get the returned error message or error object.


// Alguna operacion crud con fallos
failure: function(batch, options) {
console.log("failure");
console.log(batch.operations[0]);
console.log(batch.operations[0].request.action);
console.log(batch.operations[0].getError());
}

PankajBhargava
19 Feb 2014, 3:28 PM
batch.operations[0].getError() returns just the error code (500) and message saying Internal server error.

Isn't there a way to read the server response (which is a valid JSON) even in case of a 500 error?

Thanks.