Angular.js $http.post TypeError: Cannot read property 'data' of undefined

我们两清 提交于 2019-11-29 05:27:00

Finally got to the bottom of this. The problem was due to the following global HTTP interceptor implementation:

'use strict';
// register the interceptor as a service
angular.module('imvgm')
  .factory('httpInterceptor', ['$q', '$rootScope',  function($q, $rootScope) {

  function success(response) {
    return response;
  }

  function error(response) {
    var status = response.status;

    if (status === 401) {
      $rootScope.$broadcast('event:loginRequired');
      return
    }
    // otherwise
    return $q.reject(response);
  }

  return function(promise) {
    return promise.then(success, error);
  };

}]);

N.B

if (status === 401) {
  $rootScope.$broadcast('event:loginRequired');
  return // Returns nothing
}

FIX:

if (status === 401) {
  $rootScope.$broadcast('event:loginRequired');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!