mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 18:26:34 +02:00
Handle connection error
This commit is contained in:
parent
7f877689b2
commit
0bcc4cd9f1
1 changed files with 12 additions and 5 deletions
|
@ -28,10 +28,17 @@ export async function rateLimit(
|
||||||
|
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
const identifier = session?.user?.id || (await getIPAddress());
|
const identifier = session?.user?.id || (await getIPAddress());
|
||||||
const ratelimit = new Ratelimit({
|
try {
|
||||||
redis: kv,
|
const ratelimit = new Ratelimit({
|
||||||
limiter: Ratelimit.slidingWindow(requests, duration),
|
redis: kv,
|
||||||
});
|
limiter: Ratelimit.slidingWindow(requests, duration),
|
||||||
|
});
|
||||||
|
|
||||||
return ratelimit.limit(`${identifier}:${name}`);
|
return ratelimit.limit(`${identifier}:${name}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue