🐛 Ignore expected WhatsApp webhook errors (#2527)

- Added a viewer ORPC Sentry filter for expected production WhatsApp
webhook validation failures.
- Kept invalid webhook secret, signature, and payload responses flowing
back to callers without reporting them to Sentry.
This commit is contained in:
Baptiste Arnaud 2026-06-17 12:37:37 +02:00 committed by GitHub
parent c82ac4324a
commit 3b321f4ba1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,21 @@ const webhookUrlPaths = [
"billingRouter/webhook",
];
const expectedWhatsAppWebhookValidationErrors = [
{
code: "UNAUTHORIZED",
message: "Invalid WhatsApp webhook secret",
},
{
code: "UNAUTHORIZED",
message: "Invalid WhatsApp webhook signature",
},
{
code: "BAD_REQUEST",
message: "Invalid WhatsApp webhook payload",
},
];
const sentryMiddleware = os.middleware(async ({ next, path }) => {
try {
return await next();
@ -34,6 +49,8 @@ const sentryMiddleware = os.middleware(async ({ next, path }) => {
});
const isUnknownError = (error: unknown, path: string) => {
if (isExpectedWhatsAppWebhookValidationError(error, path)) return false;
if (
error instanceof ORPCError &&
!error.code?.includes("INTERNAL_SERVER_ERROR") &&
@ -44,6 +61,18 @@ const isUnknownError = (error: unknown, path: string) => {
return true;
};
const isExpectedWhatsAppWebhookValidationError = (
error: unknown,
path: string,
) =>
path === "chatWhatsAppRouter/productionWebhookProcedure" &&
error instanceof ORPCError &&
expectedWhatsAppWebhookValidationErrors.some(
(expectedError) =>
error.code === expectedError.code &&
error.message === expectedError.message,
);
const requireAuth = oo.spec(
os.middleware(async ({ next, context }) => {
const user = await context.authenticate();