$ http错误方法没有捕获400错误?

时间:2016-11-16 05:28:58

标签: javascript angularjs

任何线索$ http的错误方法都没有捕到400个错误的请求?

$scope.submit = function (type) {
        $http({
          method: 'GET',
          url: '/example.com',
          params: {
            type: type.type
          }
        })
        .success(handleNewParameters)
        .error(handleError);
      };

这是一个老虫,我曾经面对过它。我应该将所有成功和错误重构为当时的方法吗?

1 个答案:

答案 0 :(得分:2)

如果您已经实施了拦截器,那么如果响应状态为400,您必须转发承诺..

因此,请确保您最终拥有此代码:

            var doorsForSite = new[]
                {
                new { ControllerId ="controller1",ControllerName="Eagle",IsChecked = "false",Schedules = scheduleList,
                        Doors = new[]
                        {
                            new { DoorId="Door1",DoorName="DoorOne"},
                            new { DoorId = "Door2", DoorName = "DoorTwo" }
                        }

                    },
                new { ControllerId ="controller2",ControllerName="NetAxis",IsChecked = "false", Schedules = scheduleList,
                        Doors = new[]
                        {
                            new { DoorId=  "Door3",DoorName="DoorThree"},
                            new { DoorId = "Door4", DoorName = "DoorFour" },
                            new { DoorId = "Door5", DoorName = "DoorFive" },
                        }

                    }
            };