feat: improve unkey error handling with heavy logging for unknown errors (#23223)
* feat: improve unkey error handling with heavy logging for unknown errors - Add onError handler to all Ratelimit instances to catch unknown service errors - Log comprehensive error details including stack traces and identifiers - Return fallback response allowing requests through instead of rejecting promises - Preserve existing rate limit functionality for legitimate rate limit cases - Maintain consistency with existing timeout fallback behavior Co-Authored-By: [email protected] <[email protected]> * Update rateLimit.ts * chore: Bump @unkey/ratelimit version * Add required props to rateLimiter onError response --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
5 files changed
+24
-46
No files matched your search
@@ -77,7 +77,6 @@
|
||||
"@tanstack/react-query": "^5.17.15",
|
||||
"@team-plain/typescript-sdk": "^5.9.0",
|
||||
"@types/turndown": "^5.0.1",
|
||||
"@unkey/ratelimit": "^0.1.1",
|
||||
"@upstash/redis": "^1.35.2",
|
||||
"@vercel/edge-config": "^0.1.1",
|
||||
"@vercel/edge-functions-ui": "^0.2.1",
|
||||
|
||||
@@ -118,7 +118,6 @@
|
||||
"@daily-co/daily-js": "^0.76.0",
|
||||
"@evyweb/ioctopus": "^1.2.0",
|
||||
"@next/third-parties": "^14.2.5",
|
||||
"@unkey/ratelimit": "^2.1.2",
|
||||
"@vercel/functions": "^1.4.0",
|
||||
"city-timezones": "^1.2.1",
|
||||
"date-fns-tz": "^3.2.0",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"@formbricks/api": "^1.7.0",
|
||||
"@formbricks/js": "^2.1.0",
|
||||
"@sendgrid/client": "^7.7.0",
|
||||
"@unkey/ratelimit": "^2.1.3",
|
||||
"@vercel/og": "^0.6.3",
|
||||
"city-timezones": "^1.2.1",
|
||||
"i18next": "^23.2.3",
|
||||
|
||||
@@ -30,6 +30,16 @@ export function rateLimiter() {
|
||||
ms: 5000,
|
||||
};
|
||||
|
||||
const onError = (err: Error, identifier: string) => {
|
||||
log.error("Unkey rate limiter encountered unknown error", {
|
||||
error: err.message,
|
||||
stack: err.stack,
|
||||
identifier,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
return { success: true, limit: 10, remaining: 999, reset: 0 };
|
||||
};
|
||||
|
||||
const limiter = {
|
||||
core: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -37,6 +47,7 @@ export function rateLimiter() {
|
||||
limit: 10,
|
||||
duration: "60s",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
common: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -44,6 +55,7 @@ export function rateLimiter() {
|
||||
limit: 200,
|
||||
duration: "60s",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
forcedSlowMode: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -51,6 +63,7 @@ export function rateLimiter() {
|
||||
limit: 1,
|
||||
duration: "30s",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
api: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -58,6 +71,7 @@ export function rateLimiter() {
|
||||
limit: API_KEY_RATE_LIMIT,
|
||||
duration: "60s",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
ai: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -65,6 +79,7 @@ export function rateLimiter() {
|
||||
limit: 20,
|
||||
duration: "1d",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
sms: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -72,6 +87,7 @@ export function rateLimiter() {
|
||||
limit: 50,
|
||||
duration: "5m",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
smsMonth: new Ratelimit({
|
||||
rootKey: UNKEY_ROOT_KEY,
|
||||
@@ -79,6 +95,7 @@ export function rateLimiter() {
|
||||
limit: 250,
|
||||
duration: "30d",
|
||||
timeout,
|
||||
onError,
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
@@ -3603,6 +3603,7 @@ __metadata:
|
||||
"@formbricks/api": ^1.7.0
|
||||
"@formbricks/js": ^2.1.0
|
||||
"@sendgrid/client": ^7.7.0
|
||||
"@unkey/ratelimit": ^2.1.3
|
||||
"@vercel/og": ^0.6.3
|
||||
city-timezones: ^1.2.1
|
||||
i18next: ^23.2.3
|
||||
@@ -4311,7 +4312,6 @@ __metadata:
|
||||
"@types/stripe": ^8.0.417
|
||||
"@types/turndown": ^5.0.1
|
||||
"@types/uuid": 8.3.1
|
||||
"@unkey/ratelimit": ^0.1.1
|
||||
"@upstash/redis": ^1.35.2
|
||||
"@vercel/edge-config": ^0.1.1
|
||||
"@vercel/edge-functions-ui": ^0.2.1
|
||||
@@ -21997,40 +21997,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@unkey/api@npm:^0.19.4":
|
||||
version: 0.19.4
|
||||
resolution: "@unkey/api@npm:0.19.4"
|
||||
dependencies:
|
||||
"@unkey/rbac": ^0.1.11
|
||||
checksum: 974bb7fd5462aab55250ddd93c9785f0a1cfed19354e17bf2dbffb30ce5f3c3192dcafe71b9af36cdc7212760e1e0f3762fc8e6b0373db24c175a9e406a7a2a7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@unkey/ratelimit@npm:^0.1.1":
|
||||
version: 0.1.1
|
||||
resolution: "@unkey/ratelimit@npm:0.1.1"
|
||||
dependencies:
|
||||
"@unkey/api": ^0.19.4
|
||||
checksum: ec1d5fcf14787700d0a6e16a64e372683f9edcf08c052dbf84b8ef1c2c798d6d5162e7cb1a954d847381ab53db039747490507c0ed02c88eeea06268c02e4d56
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@unkey/ratelimit@npm:^2.1.2":
|
||||
version: 2.1.2
|
||||
resolution: "@unkey/ratelimit@npm:2.1.2"
|
||||
"@unkey/ratelimit@npm:^2.1.3":
|
||||
version: 2.1.3
|
||||
resolution: "@unkey/ratelimit@npm:2.1.3"
|
||||
dependencies:
|
||||
"@unkey/api": 2.0.3
|
||||
checksum: 645959a8f2e458fc671cc4ea3d51497e76ee9ff967a9c233dacd51caaa7d0fa20386cf47ec138026113c18527cd2a24f6f941d0b0c0bd7723c8bf9e17c87baa5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@unkey/rbac@npm:^0.1.11":
|
||||
version: 0.1.11
|
||||
resolution: "@unkey/rbac@npm:0.1.11"
|
||||
dependencies:
|
||||
zod: ^3.22.4
|
||||
zod-error: ^1.5.0
|
||||
checksum: 69fddda11453363da7b6fd881d97d21a6bb31be3c234dec51e5837634be71531ada0d69c51d37ef4d0540fb5d65ce7cbd8843380d30c70741135b27e10878e5d
|
||||
checksum: 1b95ce568eb650d5cb23a17da60e1da41d486b1831dc419cfdbec17b95927d50165c24200324ac45ff3a405ad72bb6cecc9cd0ac18177a80694f0a547fcbb59c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -24927,7 +24899,6 @@ __metadata:
|
||||
"@snaplet/copycat": ^4.1.0
|
||||
"@testing-library/jest-dom": ^5.16.5
|
||||
"@testing-library/react": ^16.0.1
|
||||
"@unkey/ratelimit": ^2.1.2
|
||||
"@vercel/functions": ^1.4.0
|
||||
"@vitest/ui": ^2.1.1
|
||||
c8: ^7.13.0
|
||||
@@ -53517,15 +53488,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"zod-error@npm:^1.5.0":
|
||||
version: 1.5.0
|
||||
resolution: "zod-error@npm:1.5.0"
|
||||
dependencies:
|
||||
zod: ^3.20.2
|
||||
checksum: 1ee6f642f3dcabc2a9610d67f1986f94c338bcf38d152e788dafc4703e488fc7624c189c5948649beb566e2d37444cea064afea662924ac2e8504920e7863ded
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"zod-prisma@npm:^0.5.4":
|
||||
version: 0.5.4
|
||||
resolution: "zod-prisma@npm:0.5.4"
|
||||
@@ -53555,7 +53517,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"zod@npm:3.22.4, zod@npm:^3.20.2, zod@npm:^3.22.4":
|
||||
"zod@npm:3.22.4, zod@npm:^3.22.4":
|
||||
version: 3.22.4
|
||||
resolution: "zod@npm:3.22.4"
|
||||
checksum: 80bfd7f8039b24fddeb0718a2ec7c02aa9856e4838d6aa4864335a047b6b37a3273b191ef335bf0b2002e5c514ef261ffcda5a589fb084a48c336ffc4cdbab7f
|
||||
|
||||
Reference in new issue
Block a user