diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index b621e6d..6d5334c 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -5,17 +5,27 @@ import { start } from "workflow/api"; import { analysisWorkflow } from "@/workflows/analysis"; export async function POST(request: Request) { - const botIdResult = await checkBotId(); - Sentry.logger.debug("BotID check result", { - isBot: botIdResult.isBot, - userAgent: request.headers.get("user-agent"), - }); - if (botIdResult.isBot) { - Sentry.logger.warn("BotID check failed", { - isBot: botIdResult.isBot, - userAgent: request.headers.get("user-agent"), - }); - return new Response("Access Denied", { status: 403 }); + if (process.env.VERCEL_ENV === "production") { + try { + const botIdResult = await checkBotId(); + Sentry.logger.debug("BotID check result", { + isBot: botIdResult.isBot, + userAgent: request.headers.get("user-agent"), + }); + if (botIdResult.isBot) { + Sentry.logger.warn("BotID check failed", { + isBot: botIdResult.isBot, + userAgent: request.headers.get("user-agent"), + }); + return new Response("Access Denied", { status: 403 }); + } + } catch (error) { + Sentry.logger.warn("BotID check threw exception", { + error: error instanceof Error ? error.message : String(error), + userAgent: request.headers.get("user-agent"), + }); + // Missing verification headers should not crash the request path. + } } const analysisStartTime = Date.now(); diff --git a/app/api/follow-up-suggestions/route.ts b/app/api/follow-up-suggestions/route.ts index db5057c..d90fee7 100644 --- a/app/api/follow-up-suggestions/route.ts +++ b/app/api/follow-up-suggestions/route.ts @@ -17,17 +17,27 @@ const followUpSuggestionsSchema = z.object({ }); export async function POST(request: Request) { - const botIdResult = await checkBotId(); - Sentry.logger.debug("BotID check result", { - isBot: botIdResult.isBot, - userAgent: request.headers.get("user-agent"), - }); - if (botIdResult.isBot) { - Sentry.logger.warn("BotID check failed", { - isBot: botIdResult.isBot, - userAgent: request.headers.get("user-agent"), - }); - return new Response("Access Denied", { status: 403 }); + if (process.env.VERCEL_ENV === "production") { + try { + const botIdResult = await checkBotId(); + Sentry.logger.debug("BotID check result", { + isBot: botIdResult.isBot, + userAgent: request.headers.get("user-agent"), + }); + if (botIdResult.isBot) { + Sentry.logger.warn("BotID check failed", { + isBot: botIdResult.isBot, + userAgent: request.headers.get("user-agent"), + }); + return new Response("Access Denied", { status: 403 }); + } + } catch (error) { + Sentry.logger.warn("BotID check threw exception", { + error: error instanceof Error ? error.message : String(error), + userAgent: request.headers.get("user-agent"), + }); + // Missing verification headers should not crash the request path. + } } const startTime = Date.now();