Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have this code :

MyService.one($routeParams.wuid).doGET('test').then(function(e){
    alert('ok');
}, function errorCallback(response){
    alert('error');
});

It calls an API i managed, but only the alert('ok') works, in the case of a 404 response, the callback isn't called i've a angularjs error in my console.

Error: c is undefined this.$get</e/A/v@http://localhost:8888/client/app/js/libs/restangular.min.js:8 Ad/e/k.promise.then/C@http://localhost:8888/client/app/js/libs/angular.min.js:92 Ad/g/<.then/<@http://localhost:8888/client/app/js/libs/angular.min.js:94 Bd/this.$get</h.prototype.$eval@http://localhost:8888/client/app/js/libs/angular.min.js:102 Bd/this.$get</h.prototype.$digest@http://localhost:8888/client/app/js/libs/angular.min.js:100 Bd/this.$get</h.prototype.$apply@http://localhost:8888/client/app/js/libs/angular.min.js:103 f@http://localhost:8888/client/app/js/libs/angular.min.js:67 E@http://localhost:8888/client/app/js/libs/angular.min.js:71 pd/</v.onreadystatechange@http://localhost:8888/client/app/js/libs/angular.min.js:72

I don't understand because the official doc says :

How can I handle errors?

Errors can be checked on the second argument of the then.

Restangular.all("accounts").getList().then(function() {
console.log("All ok"); }, function(response) { console.log("Error with status code", response.status); });

Where am i wrong ?

share|improve this question
    
Works perfectly in my code. Create a plunker or fiddle showing the error and I'm sure someone will assist. – Beyers Feb 6 '14 at 13:22
    
thanks for your response. I posted the wrong piece of code, i've corrected. it's a doGet() instead of a get(), nothing else changes – billyJoe Feb 6 '14 at 13:35

i found a way here The problem comes from my interceptor which i started on yesterday and not finished:

myApp.run(function($http, $rootScope, $location, sessionService){
    $rootScope.$on('$routeChangeStart', function(event, next, current){
        if(!sessionService.isLogged() && next.requireLogin){
            $location.path("/login");
        }

        if(sessionService.isLogged()){
            if(next.controller !== "LoginCtrl"){
                $http.defaults.headers.common['Authorization'] = 'Bearer ' + sessionService.getToken();
            }
        } 
    });

});

When i remove this interceptor, i can see my alert('error'). I guess i have to fix/end the interceptor and evertything will works fine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.