diff --git a/src/components/App.vue b/src/components/App.vue index 87b62138b..f3a7070ad 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -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