Below is the code
UserService.api.getProfile({userLogin: $scope.login}, function(res) {
_.each($scope.visibility, function(e) {
e.visible = (_.find(res, { 'roleName': e.name })) ? true : false;
});
});
And for userService.api.getProfile will be as below
angular.module('frontendApp').factory('UserService', [
'$resource',
function($resource) {
return {
api: $resource('service/authority-roles/:roleId', {}, {
getProfile: {
method: 'GET',
url: 'service/user/:userLogin/authority-roles',
isArray: true
}
It works well if the API is sending response 200. However, when the API returns the response 404, the code unable to catch the status.
I tried using "Try" and "Catch" but it's not working. I also did console.log on res.status to get the status code but the value is undefined.
The plan is, if the API returning 400 response, then alert "User Not Found" message.
Appreciate your help on this. Thanks in advance.
UserService.api.getProfile()before we could tell, but my guess is that there is a third parameter which takes the failure callback function.