1
是否可以为$ http服务实现“responseError”拦截器,只有在给定的http承诺中没有为其他地方定义的特定故障处理程序时才会触发该拦截器?
为了防止响应错误,下面的表达式$http.get(...).success(...)
将在拦截器中执行一些代码,而下面的一个$http.get(...).success(...).error(...)
不会。
是否可以为$ http服务实现“responseError”拦截器,只有在给定的http承诺中没有为其他地方定义的特定故障处理程序时才会触发该拦截器?
为了防止响应错误,下面的表达式$http.get(...).success(...)
将在拦截器中执行一些代码,而下面的一个$http.get(...).success(...).error(...)
不会。
您可以使用一个装饰:
app.config(function($provide) {
$provide.decorator('$exceptionHandler', function($delegate, $injector) {
return function $broadcastingExceptionHandler(ex, cause) {
$delegate(ex, cause);
$injector.get('$rootScope').$broadcast('exception', ex, cause);
}
});
});
本示例将捕获所有异常,虽然,但你可以检查错误,并妥善处理这个问题。