Don't retry 404's

This commit is contained in:
Natsumi
2021-08-09 03:04:29 +12:00
parent 65e5e95417
commit 4332fee486

View File

@@ -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,