4

In the following javascript, I would like to handle errors based on http error code. It is possible to handle all other types of http errors but not 407, when server sends the status as 407, jqXHR.status shows as "0" not "407". Any idea why it not shows status as 407? Is there any alternate approach to handle 407 errors in client side.

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
  }
}
Vallabha Vamaravelli
  • 1,153
  • 1
  • 9
  • 15

1 Answers1

0

You can test jqXHR.readyState and handle the 'UNSENT' state. (see here: https://xhr.spec.whatwg.org/#xmlhttprequest ) So instead of handling the 'Authentication Required' status, you could handle the 'UNSENT' state instead.

Laszlo
  • 769
  • 9
  • 19