3

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 ?

2
  • Works perfectly in my code. Create a plunker or fiddle showing the error and I'm sure someone will assist. Commented Feb 6, 2014 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 Commented Feb 6, 2014 at 13:35

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.