From 66f8b84450faa9f1765d0091b27e7ca4894b1480 Mon Sep 17 00:00:00 2001 From: kevin odwyer Date: Sat, 5 Nov 2022 13:05:28 +0000 Subject: [PATCH 1/3] add retry to notablock request --- src/components/App.vue | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components/App.vue b/src/components/App.vue index 87b62138b..8618c5010 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -294,30 +294,39 @@ 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, (errCb1) => { + that.sendNotABlockRequest(domain, (errCb2) => { + that.sendNotABlockRequest(domain, (errCb3) => { + that.$toast.error("Please unblock the following domain for Peergos to function correctly: " + + domain); + }, 4000); + }, 2000); + }, 1000); + } + }); + }, + + sendNotABlockRequest(domain, errorCb, delayMs) { + 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); }; - 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); + errorCb(e); }; - req.send(); - } - }); + }, delayMs); }, // still need to check this From 36f6fc50fa4c497d70e608bac5c3694b197e6739 Mon Sep 17 00:00:00 2001 From: kevin odwyer Date: Thu, 17 Nov 2022 07:25:03 +0000 Subject: [PATCH 2/3] handle 503 --- src/components/App.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/App.vue b/src/components/App.vue index 8618c5010..7f10663ef 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -320,6 +320,9 @@ module.exports = { req.responseType = "arraybuffer"; req.onload = function () { console.log("S3 test returned: " + req.status); + if (req.status == 503) { + errorCb(Error("Rate Limited Error")); + } }; req.onerror = function (e) { console.log('Unable to contact: ' + domain); From 99b607b09929a463929b69b33a6fb9cbb485c771 Mon Sep 17 00:00:00 2001 From: kevin odwyer Date: Thu, 17 Nov 2022 13:01:29 +0000 Subject: [PATCH 3/3] make check recursive --- src/components/App.vue | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components/App.vue b/src/components/App.vue index 7f10663ef..f3a7070ad 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -300,19 +300,18 @@ module.exports = { this.network.otherDomain().thenApply(function (domainOpt) { if (domainOpt.isPresent()) { let domain = domainOpt.get(); - that.sendNotABlockRequest(domain, (errCb1) => { - that.sendNotABlockRequest(domain, (errCb2) => { - that.sendNotABlockRequest(domain, (errCb3) => { - that.$toast.error("Please unblock the following domain for Peergos to function correctly: " + - domain); - }, 4000); - }, 2000); - }, 1000); + 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, errorCb, delayMs) { + sendNotABlockRequest(domain, callback, errorCallBack, delayMs, numberOfRetries) { + let that = this; setTimeout(() => { var req = new XMLHttpRequest(); var url = domain + "notablock"; @@ -321,12 +320,22 @@ module.exports = { req.onload = function () { console.log("S3 test returned: " + req.status); if (req.status == 503) { - errorCb(Error("Rate Limited Error")); + if (numberOfRetries <= 0) { + errorCallBack("Rate Limited Error"); + } else { + that.sendNotABlockRequest(domain, callback, errorCallBack, delayMs * 2, numberOfRetries -1); + } + } else { + callback(); } }; req.onerror = function (e) { - console.log('Unable to contact: ' + domain); - errorCb(e); + 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);