Reputation: 362
in my app I am trying to
I know how to catch error specialy for failed authorization with code 401: I have special case for this type of error.
In this scenario I just want to catch it and resend.
xhr.onloadend = function () {
switch (xhr.status) {
.
.
.
case 401:
console.log(xhr);
console.log("ERROR INVALID TOKEN");
xhr.send(); //this gives error about missing attributes
break;
}
}
I tried search online but without result.
Upvotes: 3
Views: 1611
Reputation: 82
Instead of callinfg xhr.send, you should wrap all the code of your request in a function and calling it in case of error in the request. Like below
function ErrorListener() {
makeHTTPRequest();
}
function makeHTTPRequest(){
var oReq = new XMLHttpRequest();
oReq.addEventListener("error", ErrorListener);
oReq.open("GET", "http://www.example.org/example.txt");
oReq.send();
}
Upvotes: 1