为什么角$resources没有请求和请求错误拦截器?
有办法吗?
Doc内容:
拦截器- {Object=} -拦截器对象有两个可选的方法-响应和responseError。响应和responseError拦截器都会被http响应对象调用。见$http拦截器。
发布于 2014-12-03 19:48:30
您可以实现自己的拦截器,如下所示。
app.config(function ($httpProvider) {
$httpProvider.interceptors.push('myInterceptor');
});
app.factory('myInterceptor', ['$q', function ($q) {
return {
request: function (config) {
config.headers = config.headers || {};
// insert code to populate your request header for instance
return config;
},
response: function (response) {
if (response.status === 403 || response.status === 401) {
// insert code to redirect to custom unauthorized page
}
return response || $q.when(response);
}
};
}]);希望这能帮到你。
https://stackoverflow.com/questions/27280180
复制相似问题