Skip to content

Commit 192f879

Browse files
fix: fail closed on credit check error (503 instead of 500)
Made-with: Cursor
1 parent 300e25a commit 192f879

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/app/api/gateway/proxy/route.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,19 @@ export async function POST(request: NextRequest) {
107107

108108
const { instanceId, orgId } = resolved
109109

110-
const hasFunds = await checkSufficientBalance(orgId, 0.001)
111-
if (!hasFunds) {
110+
try {
111+
const hasFunds = await checkSufficientBalance(orgId, 0.001)
112+
if (!hasFunds) {
113+
return NextResponse.json(
114+
{ error: 'Insufficient credit balance. Please add credits.' },
115+
{ status: 402 },
116+
)
117+
}
118+
} catch (err) {
119+
console.error('Credit check error:', err)
112120
return NextResponse.json(
113-
{ error: 'Insufficient credit balance. Please add credits.' },
114-
{ status: 402 },
121+
{ error: 'Billing service unavailable' },
122+
{ status: 503 },
115123
)
116124
}
117125

0 commit comments

Comments
 (0)