I made a project with angular 1.0.8 and developed the latest version, on Rails 4, everything worked fine, devise sent a 401 response when I requested api without logging in. the interceptor received 401 and processed it the way I wanted. but then decide to upgrade to the latest stable version 1.2.1, and everything worked fine (only to change the interceptor, and not return the function, returned the object), but for some reason during development it is now redirected to sign_up instead of sending an answer 401, not sure what is happening because I am testing a controller responding with the status :: unauthorized, and my interceptor did it quite well. Has anyone already had this problem when switching to 1.2.1? as I said, the only code I changed was its interceptor (it works fine with my 401 answers). all that i getThis is a status code of 302.
interceptor code:
.config(function($httpProvider){
var interceptor = function($q, $location, $rootScope) {
return {
'responseError': function(rejection) {
if (rejection.status == 401) {
$rootScope.$broadcast('event:unauthorized');
console.log('got you trying to do something illegal...')
return rejection;
}
return $q.reject(rejection);
}
};
};
$httpProvider.interceptors.push(interceptor);
})
UPDATE
So, after a while I will try to get 401 using angularjs 1.2.1 and Devise, I need:
Add the .json format to all service URLs (which require authentication, for example:) api/events/:id.json.
Be sure config.navigational_formats = []to config/initilizers/devise.rbnot have :jsonin your array.
And make sure the parameter is config.http_authenticatable_on_xhr = trueset to true.
But I still have a question, why in Angular.js 1.0.8 did this work even with an array navigational_formatshaving :json, but services don't .json?
His way to the right path?
source
share