Skip to content

Commit 9b0d01d

Browse files
committed
Make rate limiting fail-open on connection errors
Upstash Redis fetch failures were causing registration (and potentially other endpoints) to return 500 errors. Rate limiting now catches connection errors and allows the request through rather than blocking it.
1 parent 4951e67 commit 9b0d01d

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/app/api/auth/register/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ export async function POST(request: NextRequest) {
8888
);
8989
} catch (error) {
9090
dev.error("Registration error:", error, {tag: "auth"});
91-
const message = error instanceof Error ? error.message : String(error);
9291
return NextResponse.json(
93-
{ error: "An error occurred during registration", debug: message },
92+
{ error: "An error occurred during registration" },
9493
{ status: 500 },
9594
);
9695
}

src/lib/rate-limit.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,19 @@ export async function checkRateLimit(
9595
return { success: true };
9696
}
9797

98-
const result = await limiter.limit(identifier);
99-
100-
return {
101-
success: result.success,
102-
limit: result.limit,
103-
remaining: result.remaining,
104-
reset: result.reset,
105-
};
98+
try {
99+
const result = await limiter.limit(identifier);
100+
101+
return {
102+
success: result.success,
103+
limit: result.limit,
104+
remaining: result.remaining,
105+
reset: result.reset,
106+
};
107+
} catch (error) {
108+
console.error("Rate limiting error (failing open):", error);
109+
return { success: true };
110+
}
106111
}
107112

108113
/**

0 commit comments

Comments
 (0)