reset the mixin service.js and make use of the actual error message from the current service.js

pull/923/head
Molham 2025-04-20 00:58:37 +02:00 committed by Bastien Wirtz
parent ad76093a38
commit 42f3a3ee71
2 changed files with 11 additions and 22 deletions

View File

@ -44,7 +44,7 @@ export default {
}), }),
computed: { computed: {
percentage: function () { percentage: function () {
if (this.percent_blocked) { if (this.percent_blocked >= 0) {
return this.percent_blocked.toFixed(1); return this.percent_blocked.toFixed(1);
} }
return ""; return "";
@ -156,6 +156,7 @@ export default {
} }
}, },
retryWithDelay: async function () { retryWithDelay: async function () {
console.log("Retrying authentication...");
if (this.retryCount < this.maxRetries) { if (this.retryCount < this.maxRetries) {
this.retryCount++; this.retryCount++;
await new Promise(resolve => setTimeout(resolve, this.retryDelay)); await new Promise(resolve => setTimeout(resolve, this.retryDelay));
@ -175,25 +176,17 @@ export default {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}; };
const response = await this.fetch(`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`, options, false, true); const response = await this.fetch(`api/stats/summary?sid=${encodeURIComponent(this.sessionId)}`);
if (response.ok) { if (response?.queries?.percent_blocked === undefined) {
const result = await response.json();
if (result?.queries?.percent_blocked !== undefined) {
this.status = "enabled";
this.percent_blocked = result.queries.percent_blocked;
this.retryCount = 0;
} else {
throw new Error("Invalid response format"); throw new Error("Invalid response format");
} }
} else if (response.status === 401) {
this.removeCacheSession(); this.status = "enabled";
return this.retryWithDelay(); this.percent_blocked = response.queries.percent_blocked;
} else { this.retryCount = 0;
throw new Error(`HTTP error: ${response.status}`);
}
} catch (e) { } catch (e) {
if (e.message.includes("HTTP error: 401") || e.message.includes("HTTP error: 403")) { if (e.message.includes("401 error") || e.message.includes("403 error")) {
this.removeCacheSession(); this.removeCacheSession();
return this.retryWithDelay(); return this.retryWithDelay();
} }

View File

@ -12,7 +12,7 @@ export default {
} }
}, },
methods: { methods: {
fetch: function (path, init, json = true, returnFullResponse = false) { fetch: function (path, init, json = true) {
let options = {}; let options = {};
if (this.proxy?.useCredentials) { if (this.proxy?.useCredentials) {
@ -58,10 +58,6 @@ export default {
); );
} }
if (returnFullResponse) {
return response;
}
return json ? response.json() : response.text(); return json ? response.json() : response.text();
}); });
}, },