我正在制作一个http拦截器,并且我想从response
的$httpProvider
拦截器中抛出错误。
按照文档:
response
: interceptors get called with http response object. The function is free to modify the response object or create a new one. The function needs to return the response object directly, or as a promise containing the response or a new response object.
responseError
: interceptor gets called when a previous interceptor threw an error or resolved with a rejection.
我想使之与状态200的响应(我有一个条件)被路由到responseError
,我将处理做在上述报价的加粗部分错误。 不返回响应抛出以下错误:
Cannot read property 'data' of undefined
我不想返回响应,但想要将它传递给下一个处理即responseError
。
我该怎么做? 我希望我说清楚。 谢谢。
更新(下面的代码):
app.config(['$httpProvider', function($httpProvider) {
interceptor.$inject = ['$q', '$rootScope'];
$httpProvider.interceptors.push(interceptor);
function interceptor($q, $rootScope) {
return {
response: response,
responseError: responseError
};
function response(response) {
if (response.data.rs == "F") {
// I want to route it responseError -->
} else {
return response;
}
}
function responseError(response) {
// I want to handle that error here
}
}
}]);
显示你的代码队友 – Satpal
@Satpal请检查 – pranavjindal999