Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry to notablock request #430

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,30 +294,51 @@ module.exports = {
that.$store.commit("SET_NETWORK", network);
});
},

checkIfDomainNeedsUnblocking() {
if (this.network == null) return;
var that = this;
this.network.otherDomain().thenApply(function (domainOpt) {
if (domainOpt.isPresent()) {
if (domainOpt.isPresent()) {
let domain = domainOpt.get();
that.sendNotABlockRequest(domain
, () => {
//fine
}, (err) => {
that.$toast.error("Please unblock the following domain for Peergos to function correctly: " + domain + " error:" + err);
}, 1000 , 2);
}
});
},

sendNotABlockRequest(domain, callback, errorCallBack, delayMs, numberOfRetries) {
let that = this;
setTimeout(() => {
var req = new XMLHttpRequest();
var url = domainOpt.get() + "notablock";
var url = domain + "notablock";
req.open("GET", url);
req.responseType = "arraybuffer";
req.onload = function () {
console.log("S3 test returned: " + req.status);
console.log("S3 test returned: " + req.status);
if (req.status == 503) {
if (numberOfRetries <= 0) {
errorCallBack("Rate Limited Error");
} else {
that.sendNotABlockRequest(domain, callback, errorCallBack, delayMs * 2, numberOfRetries -1);
}
} else {
callback();
}
};

req.onerror = function (e) {
that.$toast.error(
"Please unblock the following domain for Peergos to function correctly: " +
domainOpt.get()
);
console.log('Unable to contact: ' + domain + ' error:' + e);
if (numberOfRetries <= 0) {
errorCallBack("Unable to contact Error");
} else {
that.sendNotABlockRequest(domain, callback, errorCallBack, delayMs * 2, numberOfRetries -1);
}
};

req.send();
}
});
}, delayMs);
},

// still need to check this
Expand Down