mirror of https://github.com/bastienwirtz/homer
reset the mixin service.js and make use of the actual error message from the current service.js
parent
ad76093a38
commit
42f3a3ee71
|
@ -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();
|
throw new Error("Invalid response format");
|
||||||
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}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.status = "enabled";
|
||||||
|
this.percent_blocked = response.queries.percent_blocked;
|
||||||
|
this.retryCount = 0;
|
||||||
} 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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue