Handling HTTP 407 error (proxy authentication required) in jquery

In the following javascript, I would like to handle errors based on the http error code. You can handle all other types of HTTP errors, but not 407, when the server sends 407 status, jqXHR.status displays as "0" and not "407". Any idea why it doesn't show 407 status? Is there an alternative approach for handling 407 client-side errors.

function handleError(jqXHR) {
  if (jqXHR.status === 500) {
      // Server side error
  } else if (jqXHR.status === 404) {
      // Not found
  } else if (jqXHR.status === 407) {
      // Proxy Authentication is required
      // This is not working, when server send http status code as 407, client side it is recieved as 0
  }
}
Run codeHide result
+4
source share
1 answer

jqXHR.readyState "UNSENT". (. : https://xhr.spec.whatwg.org/#xmlhttprequest). , " ", "UNSENT".

0

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


All Articles