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

$http in Ionic app not catching errors

我是 运行 Genymotion 模拟器下的 Ionic Android 应用程序。

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

"Cannot read property 'data' of undefined", response is undefined.

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

离子版本:1.0.0-rc.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);
//        }
//      };
//    });
//  }])