Angular HTTP:状态-1和CORS [英] Angular HTTP: Status -1 and CORS

查看:281
本文介绍了Angular HTTP:状态-1和CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的角度应用程序中,有时我们会将http状态-1返回给我们。状态-1发生在关闭的弹出窗口上,因此用户不受它的影响,只是我们的日志。

In our angular application sometimes we get http status -1 returned to us. The status -1 happens on a popup that is closed, so the user isn't affected by it, just our logs.

我试图通过执行

      switch (response.status) {
        case 0:
          break;
        case -1:
          break;
        case 401:
          localStorageService.clearAll();
          redirectToUrlAfterLogin.url = $location.path();
          $location.path('/login');

AngularJS问题#12920

我们肯定会减少登录,但仍有一些HTTP -1状态代码。有没有不同的方法我应该处理-1?

We are definitely getting less logs in, but there are still some HTTP -1 status codes. Is there a different way I should be handling the -1?

推荐答案

当请求中止或超时时,请求登记为状态-1的错误。

When the request is aborted or timed-out, the request lands as an error with status -1.

取自官方文档


此外,小于-1的状态代码归一化为零。 -1通常表示请求被中止,例如使用 config.timeout

timeout - {number | Promise} - 超时(以毫秒为单位),或承诺
应在解决时中止请求。

timeout – {number|Promise} – timeout in milliseconds, or promise that should abort the request when resolved.

这篇关于Angular HTTP:状态-1和CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆