Ionic应用程序中的$ http没有捕获错误

时间:2015-08-16 16:39:24

标签: javascript android angularjs ionic genymotion

我正在Genymotion模拟器下运行Ionic Android应用程序。

我遇到了$ http的问题。当请求成功时,一切都很好。 但是,当请求返回401/403/404代码时,Ionic框架会抛出异常:ionic.bundle.js第17288行:

  

“无法读取未定义的属性'数据',响应未定义。

似乎Ionic拦截了响应,401/403/404错误仍然试图触发.success()回调。请参阅ionic.bundle.js附带的摘录:

enter image description here

离子版:1.0.0-rc.0

1 个答案:

答案 0 :(得分:0)

问题是因为我的app.js中有一个HTTP拦截器。它似乎无害但是评论它解决了这个问题。在下面看到被评论的内容:

//  .config(['$httpProvider', function($httpProvider) {
//    $httpProvider.interceptors.push(function() {
//      return {
//        'responseError': function(rejection) {
//          var message = "HTTP Error " + rejection.statusText + "(" + rejection.status + ") on " + rejection.config.method + " " + rejection.config.url;
//
//          if (typeof rejection.data !== 'undefined')
//            message += " Error response: " + JSON.stringify(rejection.data);
//
//          // same as above
//          if (typeof _errs !== 'undefined')
//            _errs.push(new Error(message));
//          else
//            console.log(message);
//        }
//      };
//    });
//  }])