使用restangular拦截错误消息

时间:2015-03-14 18:17:15

标签: angularjs restangular

我正在尝试为所有请求创建拦截器。我决定使用restangular的[addResponseInterceptor][1]

它说

  

在我们从服务器获得每个响应后调用responseInterceptor。

我用这个函数来创建拦截器。

        rest.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
            console.log(url);
            return data;
        });

但这不是拦截错误请求。例如500.我做错了吗?或addResponseInterceptor仅用于200个回复?

1 个答案:

答案 0 :(得分:0)

不太熟悉restangular,但在角度感知器中,正常响应和错误有不同的回调。所以你是拦截正常的反应。 我相信你需要编写另一个回调函数并使用setErrorInterceptor来使它处理错误响应

相关问题