如何控制拦截器的响应

时间:2016-05-17 07:37:22

标签: angularjs rest

在Angularjs中使用拦截器,我有一个问题。我需要控制状态403,但在我的应用程序中,当API返回403时,应用程序会注销。 API将在特殊情况下返回403。我不希望拦截器进行注销,我不知道何时可以找到API返回的某些属性。

responseError: function(rejection) {

    if (rejection.status === 0) {
      //some stuff
    }
    else if (rejection.status === 401 || rejection.status === 403){
      $injector.get("Service").logout();
    }

我可以获取API在拒绝对象中返回的属性吗?

1 个答案:

答案 0 :(得分:1)

如果你在控制台中查看rejection对象,你会看到它返回的数据属性是API响应

responseError: function(rejection) {

    console.log(rejection.data) //API response data

    if (rejection.status === 0) {
      //some stuff
    }
    else if (rejection.status === 401 || rejection.status === 403){
      $injector.get("Service").logout();
    }
相关问题