Handle error calls

This commit is contained in:
2023-09-16 14:49:52 +02:00
parent 291357998c
commit f0e06891f6
4 changed files with 63 additions and 5 deletions
+22 -1
View File
@@ -6,7 +6,7 @@ import axios from "axios";
* @param debug Whether to log debug information
* @private
*/
export default async function sendHeartbeat(url: string, debug: boolean = false) {
export async function sendHeartbeat(url: string, debug: boolean = false) {
const useUrl = new URL(url);
try {
const response = await axios.get(`${useUrl.origin}/${useUrl.pathname}?status=up&msg=OK`);
@@ -20,3 +20,24 @@ export default async function sendHeartbeat(url: string, debug: boolean = false)
console.error(`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${error}`);
}
}
/**
* Sends a shutdown notification to the provided URL
* @param url The URL to send the notification to
* @param debug Whether to log debug information
* @private
*/
export async function sendShutdownNotification(url: string, msg: string = "Shutdown",debug: boolean = false) {
const useUrl = new URL(url);
try {
const response = await axios.get(`${useUrl.origin}/${useUrl.pathname}?status=DOWN&msg=${msg}`);
if (debug)
console.log(
`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${response.status} ${response.statusText} - ${
response.data
}`
);
} catch (error) {
console.error(`[eu.astrogd.uptime-kuma-push-monitor] (${new Date().toISOString()}) <${url}>: ${error}`);
}
}