From 6bffae039d1cc9e821087d8c783e7d1c68e61925 Mon Sep 17 00:00:00 2001 From: Lukasdotcom Date: Mon, 11 Jul 2022 11:25:18 -0400 Subject: [PATCH] Program still works if github api fails to respond or is rate limiting you --- scripts/entrypoint.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/entrypoint.mjs b/scripts/entrypoint.mjs index 392566b9..813689c5 100644 --- a/scripts/entrypoint.mjs +++ b/scripts/entrypoint.mjs @@ -96,14 +96,18 @@ async function startUp() { updateData() // Checks if this is the latest version and if it does adds data async function updateInfo() { + console.log("Checking for updates") + const releases = await fetch("https://api.github.com/repos/lukasdotcom/Bundesliga/releases").then((res) => res.ok ? res.json() : {}) + if (releases[0] === undefined || releases[0].tag_name === undefined) { + console.log("Failed to get version data from github api") + return + } const connection = createConnection({ host : process.env.MYSQL_HOST, user : process.env.MYSQL_USER, password : process.env.MYSQL_PASSWORD, database : process.env.MYSQL_DATABASE }) - console.log("Checking for updates") - const releases = await fetch("https://api.github.com/repos/lukasdotcom/Bundesliga/releases").then((res) => res.json()) if (version.version !== releases[0].tag_name) { connection.query("INSERT INTO data (value1, value2) VALUES('updateProgram', ?) ON DUPLICATE KEY UPDATE value2=?",[releases[0].html_url, releases[0].html_url]) } else {