Commit b15909cf authored by Evren Kutar's avatar Evren Kutar

400 hatasında yeniden yükleme ve 401 hatasında login sayfasına yönlendirme

parent 896f3a21
...@@ -101,7 +101,7 @@ app.config(['$routeProvider', function ($routeProvider) { ...@@ -101,7 +101,7 @@ app.config(['$routeProvider', function ($routeProvider) {
controller: 'StaffListCtrl', controller: 'StaffListCtrl',
resolve: { resolve: {
loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) { loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('components/student/student_controller.js'); return $ocLazyLoad.load('components/staff/staff_controller.js');
}], }],
loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) { loadMyService: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('zetalib/forms/form_service.js'); return $ocLazyLoad.load('zetalib/forms/form_service.js');
...@@ -144,4 +144,27 @@ app.config(['$routeProvider', function ($routeProvider) { ...@@ -144,4 +144,27 @@ app.config(['$routeProvider', function ($routeProvider) {
} }
} }
}); });
}); }).config(['$httpProvider', function ($httpProvider) {
\ No newline at end of file /**
* the interceptor for all requests to check response
* 4xx - 5xx errors will be handled here
*/
$httpProvider.interceptors.push(function ($q) {
return {
'response': function (response) {
//Will only be called for HTTP up to 300
return response;
},
'responseError': function (rejection) {
// if unauthorized then redirect to login page
if(rejection.status === 400) {
location.reload();
}
if(rejection.status === 401) {
location.path('#/login');
}
return $q.reject(rejection);
}
};
});
}]);
\ No newline at end of file
...@@ -85,5 +85,19 @@ describe('zaerp.auth module', function () { ...@@ -85,5 +85,19 @@ describe('zaerp.auth module', function () {
}) })
); );
// todo: test in case of 401 reload
//it('unauthorized 401 should redirect to login',
// inject(function ($httpBackend, $http, $location, $window) {
//
// $httpBackend.whenGET('http://127.0.0.1:8000/#/dashboard').respond(401, '');
//
// $http.get('http://127.0.0.1:8000/#/dashboard');
// expect($window.location == '/#/login');
//
// $httpBackend.flush();
// })
//);
}); });
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment