I would like to know how to handle exceptions in angularjs. What artifacts can I use or how to implement error handling.
I have the following code:
This is an example of my JSON. Now what I would like to validate is if the list "listProducts" exists or comes empty.
[{
"estado":false,
"id":1,
"direccion":"Calle José Galvez 1575 Dpto 201 Lince",
"tipodeFactura":"Facturación",
"asociado":"998882591",
"listadoProductos": [{
"idProducto":"0001",
"nombreProducto": "Cajita Feliz"
}
],
"fault":[{
"errorFun":[{
"idError":"01",
"mensaje":"errorfunc"
}],
"errorTec":[{
"idError":"01",
"mensaje":"errorTec"
}]
}]
}]
For example I have the following call $http
from my service:
appServices.service('productoServicio', ['$http', function($http) {
var UrlProductosServicios = 'http://172.19.74.235:8909/ProductoServiciosResulFull/service/obtenerServicios/p';
this.getListProductos = function () {
return $http.get(UrlProductosServicios);
};
The field "fault"
of the Json must bring the errors of coding, functionality, timeout or availability of the server. How can I implement the handling of these errors?
Would you appreciate your help if you can give me some idea of how to handle this?
I also attach the method getListProductos of my service in my controller to my consumption
productoServicio.getListProductos().then(function (response) {
$scope.ListProducto = response.data;
$scope.estadoConsumer = true;
}, function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
$scope.estado = false;
});
Thanks in advance