fix(convex): use ConvexError for AUTH_REQUIRED so Sentry treats it as expected (#3216)

* fix(convex): use ConvexError for AUTH_REQUIRED so Sentry treats it as expected

WORLDMONITOR-N3: 8 events / 2 users from server-side Convex reporting
`Uncaught Error: Authentication required` thrown by requireUserId() when
a query fires before the WebSocket auth handshake completes. Every other
business error in this repo uses ConvexError("CODE"), which Convex's
server-side Sentry integration treats as expected rather than unhandled.

Migrate requireUserId to ConvexError("AUTH_REQUIRED") (no consumer parses
the message string — only a code comment references it) and add a matching
client-side ignoreErrors pattern next to the existing API_ACCESS_REQUIRED
precedent, as defense-in-depth against unhandled rejections reaching the
browser SDK.

* fix(sentry): drop broad AUTH_REQUIRED ignoreErrors — too many real call sites

Review feedback: requireUserId() backs user-initiated actions (checkout,
billing portal, API key ops), not just the benign query-race path. A bare
`ConvexError: AUTH_REQUIRED` message-regex in ignoreErrors has no stack
context, so a genuine auth regression breaking those flows for signed-in
users would be silently dropped. The server-side ConvexError migration in
convex/lib/auth.ts is enough to silence WORLDMONITOR-N3; anything that
still reaches the browser SDK should surface.
This commit is contained in:
Elie Habib
2026-04-20 01:35:33 +04:00
committed by GitHub
parent 4c9888ac79
commit fc0c6bc163

View File

@@ -1,3 +1,4 @@
import { ConvexError } from "convex/values";
import { QueryCtx, MutationCtx, ActionCtx } from "../_generated/server";
export const DEV_USER_ID = "test-user-001";
@@ -55,7 +56,11 @@ export async function requireUserId(
): Promise<string> {
const userId = await resolveUserId(ctx);
if (!userId) {
throw new Error("Authentication required");
// Throw as ConvexError so Convex's server-side Sentry integration treats it
// as an expected business error (WebSocket/auth races on query fire) rather
// than reporting every unauthed query fire as an unhandled exception
// (WORLDMONITOR-N3).
throw new ConvexError("AUTH_REQUIRED");
}
return userId;
}