Skip to content

Commit

Permalink
fix: catch exception when checking default branch (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <grant@acorn.io>
  • Loading branch information
g-linville authored Aug 21, 2024
1 parent f2833a7 commit 1599adb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/server/api/[...slug].post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('/') }` : ''
Expand All @@ -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)
}
Expand Down

0 comments on commit 1599adb

Please # to comment.