From 42f3a3ee71e236f6a3871febbafd8a11a83fae85 Mon Sep 17 00:00:00 2001 From: Molham Date: Sun, 20 Apr 2025 00:58:37 +0200 Subject: [PATCH] reset the mixin service.js and make use of the actual error message from the current service.js --- src/components/services/PiHole.vue | 27 ++++++++++----------------- src/mixins/service.js | 6 +----- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/components/services/PiHole.vue b/src/components/services/PiHole.vue index 1703bf3..654cd86 100644 --- a/src/components/services/PiHole.vue +++ b/src/components/services/PiHole.vue @@ -44,7 +44,7 @@ export default { }), computed: { percentage: function () { - if (this.percent_blocked) { + if (this.percent_blocked >= 0) { return this.percent_blocked.toFixed(1); } return ""; @@ -156,6 +156,7 @@ export default { } }, retryWithDelay: async function () { + console.log("Retrying authentication..."); if (this.retryCount < this.maxRetries) { this.retryCount++; await new Promise(resolve => setTimeout(resolve, this.retryDelay)); @@ -175,25 +176,17 @@ export default { '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) { - 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"); - } - } else if (response.status === 401) { - this.removeCacheSession(); - return this.retryWithDelay(); - } else { - throw new Error(`HTTP error: ${response.status}`); + if (response?.queries?.percent_blocked === undefined) { + throw new Error("Invalid response format"); } + + this.status = "enabled"; + this.percent_blocked = response.queries.percent_blocked; + this.retryCount = 0; } 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(); return this.retryWithDelay(); } diff --git a/src/mixins/service.js b/src/mixins/service.js index f1e77bf..d52fc29 100644 --- a/src/mixins/service.js +++ b/src/mixins/service.js @@ -12,7 +12,7 @@ export default { } }, methods: { - fetch: function (path, init, json = true, returnFullResponse = false) { + fetch: function (path, init, json = true) { let options = {}; if (this.proxy?.useCredentials) { @@ -58,10 +58,6 @@ export default { ); } - if (returnFullResponse) { - return response; - } - return json ? response.json() : response.text(); }); },