Skip to content

Commit 1599adb

Browse files
authored
fix: catch exception when checking default branch (#18)
Signed-off-by: Grant Linville <grant@acorn.io>
1 parent f2833a7 commit 1599adb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/server/api/[...slug].post.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ export default defineEventHandler(async (event) => {
5151
const [owner, repo, ...subdirs] = url.replace(/^(https?:\/\/)?(www\.)?github\.com\//, '').split('/')
5252

5353
// find the default branch name
54-
console.log(`Checking GitHub API for repo ${owner}/${repo}`)
55-
const branchResponse = await octokit.request(`GET https://api.github.com/repos/${ owner }/${ repo }`)
56-
console.log(`Got response code ${branchResponse.status} from GitHub API`)
57-
const branch = branchResponse.data.default_branch
54+
let branch = 'main';
55+
try {
56+
const branchResponse = await octokit.request(`GET https://api.github.com/repos/${ owner }/${ repo }`)
57+
branch = branchResponse.data.default_branch
58+
} catch (e) {} // don't care about the exception; just fall back to main
5859

5960
// construct the path to the tool.gpt file
6061
const path = subdirs.length > 0 ? `${ subdirs.join('/') }` : ''
@@ -64,7 +65,6 @@ export default defineEventHandler(async (event) => {
6465

6566
if (!toolResponse.ok) {
6667
// clean-up any existing tools if the tool.gpt file is no longer found or is private
67-
console.log(`Got response code ${toolResponse.status} from raw.githubusercontent.com/${owner}/${repo}/${branch}/${path}/tool.gpt`)
6868
if (toolResponse.status === 404 || toolResponse.status === 403) {
6969
await db.removeToolForUrlIfExists(url)
7070
}

0 commit comments

Comments
 (0)