Skip to content

[Bug] Unhandled exception on database failure in /api/metrics/repos — Supabase query outside try/catch block #2234

@shauryavardhan1307

Description

@shauryavardhan1307

Problem

In app/api/metrics/repos/route.ts, the query to
supabaseAdmin.from("user_github_accounts") is placed
OUTSIDE the try/catch block (which starts at line 325).

If Supabase is unavailable or offline, this throws an
unhandled exception that crashes the route and returns
a generic 500 error instead of a structured error
response like other database-dependent endpoints.

Impact

  • Route crashes with unhandled exception when Supabase
    is unavailable
  • Returns generic 500 instead of structured 502 error
  • Inconsistent error handling compared to other endpoints

Proposed Fix

Move the user_github_accounts query inside the
existing try/catch block:

try {
  // Move this inside:
  const { data: accountData } = await supabaseAdmin
    .from("user_github_accounts")
    .select(...)
    
  // ... rest of existing try block
} catch (error) {
  return NextResponse.json(
    { error: "Database unavailable" }, 
    { status: 502 }
  );
}

File

app/api/metrics/repos/route.ts — line ~325

I'd like to work on this fix if approved!
GSSoC '26 contributor.

Metadata

Metadata

Labels

gssoc:assignedGSSoC: Issue assigned to a contributor

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions