From 1599adb4488f01ab908522df521566c4e7ab85bb Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Wed, 21 Aug 2024 13:35:45 -0400 Subject: [PATCH] fix: catch exception when checking default branch (#18) Signed-off-by: Grant Linville --- src/server/api/[...slug].post.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/api/[...slug].post.ts b/src/server/api/[...slug].post.ts index bf0e80a..b78db7b 100644 --- a/src/server/api/[...slug].post.ts +++ b/src/server/api/[...slug].post.ts @@ -51,10 +51,11 @@ export default defineEventHandler(async (event) => { const [owner, repo, ...subdirs] = url.replace(/^(https?:\/\/)?(www\.)?github\.com\//, '').split('/') // find the default branch name - console.log(`Checking GitHub API for repo ${owner}/${repo}`) - const branchResponse = await octokit.request(`GET https://api.github.com/repos/${ owner }/${ repo }`) - console.log(`Got response code ${branchResponse.status} from GitHub API`) - const branch = branchResponse.data.default_branch + let branch = 'main'; + try { + const branchResponse = await octokit.request(`GET https://api.github.com/repos/${ owner }/${ repo }`) + branch = branchResponse.data.default_branch + } catch (e) {} // don't care about the exception; just fall back to main // construct the path to the tool.gpt file const path = subdirs.length > 0 ? `${ subdirs.join('/') }` : '' @@ -64,7 +65,6 @@ export default defineEventHandler(async (event) => { if (!toolResponse.ok) { // clean-up any existing tools if the tool.gpt file is no longer found or is private - console.log(`Got response code ${toolResponse.status} from raw.githubusercontent.com/${owner}/${repo}/${branch}/${path}/tool.gpt`) if (toolResponse.status === 404 || toolResponse.status === 403) { await db.removeToolForUrlIfExists(url) }