Angular.js:访问HTTP Response Interceptor中的JSON

时间:2014-10-15 13:10:53

标签: json angularjs express

我发送HTTP:

res.status(404).send({message: 'O Captain! My Captain!'}); 

我在Angular服务中拦截HTTP:

appServices.factory('ErrorInterceptor', ['$q', '$injector', function($q, $injector) {
    var ErrorInterceptor = {
        responseError: function(response) {

            if (response.status == 404){

                console.log("[ErrorInterceptor] :" + response.status)      
                console.log("[ErrorInterceptor] :" + response.message)     
            }

            return $q.reject(response);
        }
    };
    return ErrorInterceptor;
}]);

仅清除状态404,而不是我的JSON message成员的值。

1 个答案:

答案 0 :(得分:1)

解决方案

console.log("[ErrorInterceptor] data.error:" + response.data.message)  

萤火虫

O Captain! My Captain!