mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-22 21:06:40 +08:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import * as Sentry from "@sentry/nextjs";
|
|
import type { TRPCError } from "@trpc/server";
|
|
|
|
const ignoreTrpcMessages = [
|
|
"potential malicious typebot",
|
|
"typebot not found",
|
|
"workspace not found",
|
|
"workspace with same name already exists",
|
|
"no typebots found",
|
|
];
|
|
|
|
Sentry.init({
|
|
dsn: process.env.SENTRY_DSN,
|
|
environment: process.env.NODE_ENV,
|
|
tracesSampleRate: 1,
|
|
beforeSend: (event, hint) => {
|
|
const exception = hint.originalException;
|
|
if (isTrpcError(exception)) {
|
|
if (
|
|
ignoreTrpcMessages.some((message) =>
|
|
exception.message.toLowerCase().includes(message.toLowerCase()),
|
|
)
|
|
)
|
|
return null;
|
|
if (exception.cause?.name === "ClientToastError") return null;
|
|
if (
|
|
exception.code === "BAD_REQUEST" &&
|
|
exception.cause?.name === "ZodError" &&
|
|
event.contexts?.trpc?.procedure_path === "typebot.importTypebot"
|
|
)
|
|
return null;
|
|
if (
|
|
exception.code === "CONFLICT" &&
|
|
event.contexts?.trpc?.procedure_path === "typebot.updateTypebot"
|
|
)
|
|
return null;
|
|
if (exception.code === "UNAUTHORIZED") return null;
|
|
}
|
|
return event;
|
|
},
|
|
});
|
|
|
|
const isTrpcError = (err: unknown): err is TRPCError => {
|
|
if (!err || typeof err !== "object") return false;
|
|
return "name" in err && err.name === "TRPCError";
|
|
};
|