Answer the question
In order to leave comments, you need to log in
Whether probably to change result of request in interceptor'e?
For example, if the request fell with a timeout, replace the response with some other one.
Answer the question
In order to leave comments, you need to log in
/*global angular*/
(function () {
'use strict';
angular
.module('App')
.factory('httpErrorResponceInterceptor', ['$q', '$injector', '$rootScope', '$log',
httpErrorResponceInterceptor]);
/**
* Интерсептор для перехвата ответов сервера, которые содержат ошибку.
* Реализует обработку ошибочных ответов сервера (http кодов).
* Реагирует только на коды 400, 401, 403, 404, и 500
*
* @name httpErrorResponceInterceptor
*/
function httpErrorResponceInterceptor($q, $injector, $rootScope, $log) {
var self = {};
self.responseError = function (response) {
if (response.status == 401){
return $q.reject(response);
}
else if (response.status == 400){
return $q.reject(response);
}
else if (response.status == 403) {
return $q.reject(response);
}
else if (response.status == 404) {
return $q.reject(response);
}
else if (response.status == 500) {
return $q.reject(response);
}
return $http(response.config);
};
return self;
}
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question