From 3fcbd6a3fc96ab75839b1542784c3db3d77ed764 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:16:21 +0000 Subject: [PATCH] chore: catch config not found hopefully it does throw --- src/utils/helpers.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 593dabf..71da9ac 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -30,18 +30,22 @@ export async function getUbiquiBotConfig(octokit: Octokit, owner: string, repo: } async function fetchConfig(octokit: Octokit, owner: string, repo: string): Promise { - const response = await octokit.rest.repos.getContent({ - owner, - repo, - path: ".github/ubiquibot-config.yml", - }); - - // Check if the response data is a file and has a content property - if ("content" in response.data && typeof response.data.content === "string") { - // Convert the content from Base64 to string and parse the YAML content - const content = atob(response.data.content).toString(); - return yaml.load(content) as UbiquiBotConfig; - } else { + try { + const response = await octokit.rest.repos.getContent({ + owner, + repo, + path: ".github/ubiquibot-config.yml", + }); + // Check if the response data is a file and has a content property + if ("content" in response.data && typeof response.data.content === "string") { + // Convert the content from Base64 to string and parse the YAML content + const content = atob(response.data.content).toString(); + return yaml.load(content) as UbiquiBotConfig; + } else { + return null; + } + } catch (err) { + console.error(err); return null; } }