From 4332fee486e3a39204f3e8bf2147b206213c7923 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Mon, 9 Aug 2021 03:04:29 +1200 Subject: [PATCH] Don't retry 404's --- html/src/app.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/html/src/app.js b/html/src/app.js index 99c392fb..8808a0f1 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -352,6 +352,7 @@ speechSynthesis.getVoices(); }; API.pendingGetRequests = new Map(); + API.failedGetRequests = new Map(); API.call = function (endpoint, options) { var init = { @@ -361,6 +362,14 @@ speechSynthesis.getVoices(); }; var { params } = init; if (init.method === 'GET') { + // don't retry recent 404 + if (this.failedGetRequests.has(endpoint)) { + var lastRun = this.failedGetRequests.get(endpoint); + if (lastRun >= Date.now() - 900000) { //15mins + throw new Error(`Bailing request due to past 404, ${endpoint}`); + } + this.failedGetRequests.delete(endpoint); + } // transform body to url if (params === Object(params)) { var url = new URL(init.url); @@ -426,8 +435,12 @@ speechSynthesis.getVoices(); message: 'Avatar private or deleted', type: 'error' }); + $app.avatarDialog.visable = false; throw new Error('404: Can\'t find avatarǃ'); } + if ((init.method === 'GET') && (status === 404)) { + this.failedGetRequests.set(endpoint, Date.now()); + } if (data.error === Object(data.error)) { this.$throw( data.error.status_code || status,