为什么 Angularjs responseError 拦截器返回状态码 -1

Why is Angularjs responseError interceptor returning a status code of -1

我希望能够在我的 angularjs 项目中处理 401 状态代码。我已经尝试了几种不同的响应拦截器变体,但它们都 return 代码为 -1。我想了解为什么会这样。使用 Angularjs v1.5.8.

myApp.factory('httpResponseInterceptor', function () {
  return {
    responseError: function (config) {
      console.log(config.status);
      //The above prints out -1 to the console
      return config;
    }
  };
});

myApp.config(function ($httpProvider) {
  $httpProvider.interceptors.push('httpResponseInterceptor');
});

是CORS问题,CORS是Cross-Origin Resource Sharing。 您必须从服务器端启用 CORS。