Handle error calls
This commit is contained in:
+22
-1
@@ -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}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user