mirror of https://github.com/bastienwirtz/homer
better handle errors and set the subtitle as a message holder for errors
parent
28ad80369f
commit
4684b23a8c
|
@ -42,7 +42,7 @@ export default {
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
percentage: function () {
|
percentage: function () {
|
||||||
if (this.percent_blocked) {
|
if (typeof this.percent_blocked === 'number' && this.percent_blocked >= 0) {
|
||||||
return this.percent_blocked.toFixed(1);
|
return this.percent_blocked.toFixed(1);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -66,6 +66,11 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
handleError: function (error, status) {
|
||||||
|
console.error(error);
|
||||||
|
this.subtitle = error;
|
||||||
|
this.status = status;
|
||||||
|
},
|
||||||
startStatusPolling: function () {
|
startStatusPolling: function () {
|
||||||
this.fetchStatus();
|
this.fetchStatus();
|
||||||
// Set the interval to the checkInterval or default to 5 minutes
|
// Set the interval to the checkInterval or default to 5 minutes
|
||||||
|
@ -93,7 +98,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to load cached session:", e);
|
this.handleError(`Failed to load cached session: ${e}`, "error");
|
||||||
this.removeCacheSession();
|
this.removeCacheSession();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -110,15 +115,14 @@ export default {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to delete session:", e);
|
this.handleError(`Failed to delete session: ${e}`, "error");
|
||||||
} finally {
|
} finally {
|
||||||
this.removeCacheSession();
|
this.removeCacheSession();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
authenticate: async function () {
|
authenticate: async function () {
|
||||||
if (!this.item.apikey) {
|
if (!this.item.apikey) {
|
||||||
console.error("API key is required for PiHole authentication");
|
this.handleError("API key is required for PiHole authentication", "disabled");
|
||||||
this.status = "disabled";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +149,7 @@ export default {
|
||||||
}
|
}
|
||||||
throw new Error("Invalid authentication response");
|
throw new Error("Invalid authentication response");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Authentication failed:", e);
|
this.handleError(`Authentication failed: ${e}`, "disabled");
|
||||||
this.status = "disabled";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -184,12 +187,11 @@ export default {
|
||||||
throw new Error(`HTTP error: ${response.status}`);
|
throw new Error(`HTTP error: ${response.status}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to fetch status:", e);
|
if (e.includes("HTTP error: 401") || e.includes("HTTP error: 403")) {
|
||||||
if (e.message.includes("HTTP error: 401") || e.message.includes("HTTP error: 403")) {
|
|
||||||
this.removeCacheSession();
|
this.removeCacheSession();
|
||||||
return this.retryWithDelay();
|
return this.retryWithDelay();
|
||||||
}
|
}
|
||||||
this.status = "disabled";
|
this.handleError(`Failed to fetch status: ${e}`, "disabled");
|
||||||
this.removeCacheSession();
|
this.removeCacheSession();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -214,8 +216,7 @@ export default {
|
||||||
throw new Error(`HTTP error: ${response.status}`);
|
throw new Error(`HTTP error: ${response.status}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to fetch v5 status:", e);
|
this.handleError(`Failed to fetch v5 status: ${e}`, "error");
|
||||||
this.status = "error";
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue