diff --git a/src/app/api/generate/route.ts b/src/app/api/generate/route.ts index 3c7f56f..c0afdca 100644 --- a/src/app/api/generate/route.ts +++ b/src/app/api/generate/route.ts @@ -56,12 +56,24 @@ export async function POST(req: Request) { { status: 400 }, ); } - - const [repoInfo, repoContents] = await Promise.all([ + let repoInfo, repoContents; + [repoInfo, repoContents] = await Promise.all([ getRepoData(owner, repo), getRepoContents(owner, repo), ]); + // If the Octokit helpers swallow errors and return null/empty results, + // handle that case explicitly here instead of relying on try/catch. + if (!repoInfo) { + return NextResponse.json( + { + error: + "Unable to fetch repository from GitHub. Please verify the repository exists, is public, and the URL is correct.", + }, + { status: 400 }, + ); + } + const files = Array.isArray(repoContents) ? repoContents.map((f: { name: string }) => f.name) : []; @@ -154,7 +166,7 @@ export async function POST(req: Request) { console.error("README Generation Failed:", message); return NextResponse.json( - { error: "Failed to generate README. Check your URL and try again." }, + { error: "AI generation failed. Please try again in a moment." }, { status: 500 }, ); }