Angular HTTP: status -1 and CORS

In our angular application, sometimes we get the return status of http -1. State -1 occurs in a popup that is closed, so the user does not affect it, just our logs.

I tried to handle this by doing

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

What was proposed in AngularJS Issue # 12920

We definitely get fewer logs, but there are still some HTTP -1 status codes. Is there any other way that I should handle -1?

+4
source share
2 answers

When a request is interrupted or aborted, the request is assigned as an error with a status of -1.

:

, , -1, . -1 , , . config.timeout.

timeout – {number|Promise} - - .

+2

, -1 , - .

HTTP-, . , XMLHttpRequest Fetch . , -, XMLHttpRequest Fetch HTTP- . -, .

Cross-Origin (CORS) , . CORS API, XMLHttpRequest Fetch - HTTP- -.

. CORS, -.

+1

Source: https://habr.com/ru/post/1628899/


All Articles