Angularjs Angular-404HTTP拦截器

Angularjs Angular-404HTTP拦截器,angularjs,node.js,Angularjs,Node.js,每当我的节点服务器返回404错误时,我希望我的Angular应用程序和指向特定路由的用户能够截获该错误 我正试图构建一个简单的拦截器来实现这一点,但是它似乎没有返回任何东西 当404出现时,关于为什么这段代码不会打印任何内容的任何指针(我已经通过查看页眉确认了这一点): 以及守则: .config(function($httpProvider) { //Ignore this authInceptor is for saving my JWT's $httpProvider.inter

每当我的节点服务器返回404错误时,我希望我的Angular应用程序和指向特定路由的用户能够截获该错误

我正试图构建一个简单的拦截器来实现这一点,但是它似乎没有返回任何东西

当404出现时,关于为什么这段代码不会打印任何内容的任何指针(我已经通过查看页眉确认了这一点):

以及守则:

.config(function($httpProvider) {
  //Ignore this authInceptor is for saving my JWT's
  $httpProvider.interceptors.push('authInterceptor');

  //This is the one I'm having issue with
  $httpProvider.interceptors.push(function myErrorInterceptor($window, $location) {
    return {
      requestError: function(res){
        if (res.status === 404) {
          console.log('You're In - Now do some more stuff')
        }
        return res;
      }
    }
  })
})
更新: 因此,除此之外,我已经意识到在我的节点端-我有

//This section is to handle Angular HTML5Mode Urls
//Have to rewrite all your links to entry point of your application (e.g. index.html)
app.get('/*', function(req, res) {
  res.sendFile(__dirname + '/site/index.html')
});

所以这里的另一个问题是,
app.get(“/*”
无法区分角度路由允许的内容-那么我如何让它意识到这一点?(不希望在数组中复制代码)

我认为问题在于您正在连接到
requestError
,而不是
responseError
。请尝试以下操作:

.config(function($httpProvider) {
  //Ignore this authInceptor is for saving my JWT's
  $httpProvider.interceptors.push('authInterceptor');

  //This is the one I'm having issue with
  $httpProvider.interceptors.push(function myErrorInterceptor($window, $location) {
    return {
      responseError: function(res){
        if (res.status === 404) {
          console.log('You're In - Now do some more stuff')
        }
        return res;
      }
    }
  })
});

我认为问题在于您正在连接到
requestError
,而不是
responseError
。请尝试以下操作:

.config(function($httpProvider) {
  //Ignore this authInceptor is for saving my JWT's
  $httpProvider.interceptors.push('authInterceptor');

  //This is the one I'm having issue with
  $httpProvider.interceptors.push(function myErrorInterceptor($window, $location) {
    return {
      responseError: function(res){
        if (res.status === 404) {
          console.log('You're In - Now do some more stuff')
        }
        return res;
      }
    }
  })
});

这里有一个可能有用的方法。另外,请注意被拒绝的返回承诺。如果您已经处理了404/将所有请求路由回angular入口点(对于HTML5模式)在服务器/节点端,它在哪种情况下抛出404?下面是一个可能有用的例子。另外,请注意被拒绝的返回承诺。如果您在服务器/节点端处理了404/将所有请求路由回angular入口点(对于HTML5模式),它在哪种情况下抛出404?