feat: add rate limiting and more error handling to Cal.ai (#11898)

Co-authored-by: tedspare <[email protected]>
This commit is contained in:
DexterStoreyandtedspare authored and GitHub committed 2023-10-17 18:26:49 +00:00
1 parent 4b8bdeba74
commit 9e927af813
5 files changed
+49 -13

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
import { TRPCError } from "@calcom/trpc";
import { TRPCError } from "@calcom/trpc/server";
import type { RateLimitHelper } from "./rateLimit";
import { rateLimiter } from "./rateLimit";
+7 -1
View File
@@ -7,7 +7,7 @@ import logger from "./logger";
const log = logger.getChildLogger({ prefix: ["RateLimit"] });
export type RateLimitHelper = {
rateLimitingType?: "core" | "forcedSlowMode" | "common" | "api";
rateLimitingType?: "core" | "forcedSlowMode" | "common" | "api" | "ai";
identifier: string;
};
@@ -75,6 +75,12 @@ export function rateLimiter() {
prefix: "ratelimit:api",
limiter: Ratelimit.fixedWindow(10, "60s"),
}),
ai: new Ratelimit({
redis,
analytics: true,
prefix: "ratelimit",
limiter: Ratelimit.fixedWindow(20, "1d"),
}),
};
async function rateLimit({ rateLimitingType = "core", identifier }: RateLimitHelper) {