I am trying to neatly manage service function calls from the controller while handling errors from the API.
However when I do the following, I still get this is showing even with 403 and 404 errors
in my console even when the API throws back a 403 or 404.
I am assuming this could work if I added catch
in my services file but I would prefer keep this managed from the controller. Is this possible?
Controller:
angular.module('EnterDataCtrl', []).controller('EnterDataController', ['$scope', 'Data', '$state', function ($scope, Data, $state) {
vm = this;
vm.getRules = function (e, rule_query, data) {
if (e.keyCode == 13) {
Data.getRules(rule_query,data).then(function (data) {
console.log('this is showing even with 403 and 404 errors');
}).catch(function(res) {
console.log(res);
});
}
}
}]);
Service:
angular.module('EnterDataService', []).factory('Data', ['$http', function ($http) {
return {
getRules: function getRules(rule_query,data) {
var apiBase = apiUrl + 'get-rules';
var config = {
handleError:true,
params: {
rule_query: rule_query,
data : data
}
};
return $http.get(apiBase, config).catch(function () {});
}
}
}]);