Repository: supabase/supabase
File: apps/studio/lib/error-reporting.ts (TypeScript)

Code before:
  'You attempted to send email to an inactive recipient',
  'New password should be different from the old password',
  'Invalid TOTP code entered',
  'No SSO provider assigned for this domain',
  // Project creation errors
  'The following organization members have reached their maximum limits for the number of active free projects',
  'db_pass must be longer than or equal to 4 characters',
  'There are overdue invoices in the organization(s)',
  'name should not contain a . string',
  'Project creation in the Supabase dashboard is disabled for this Vercel-managed organization.',
  'Your account, which is handled by the Fly Supabase extension, cannot access this endpoint.',
  'already exists in your organization.',
]

/**
 * Captures a critical error to Sentry, filtering out whitelisted errors.
 *
 * @param error - The error object (ResponseError, Error, or any object with a message property)
 * @param context - The context/action that failed (e.g., 'reset password', 'sign up', 'create project')
 *   Attached as the `context` tag on the Sentry event.
 */
export function captureCriticalError(
  error: ResponseError | Error | { message: string },
  context: string
): void {
  const errorMessage =
    error instanceof Error ? error.message : (error as { message: string }).message
  if (!errorMessage) {
    return
  }

  if (error instanceof ResponseError) {
    handleResponseError(error, context)
    return
  }
  if (error instanceof Error) {
    handleError(error, context)
    return
  }

  handleUnknownError(error, context)
}

function handleResponseError(error: ResponseError, context: string) {
  const { code, message, requestPathname } = error
  if (!requestPathname || !code) {
    captureMessage({
      message: `Response Error (no code or requestPathname) w/ message: ${error.message}`,
      context,
    })
    return

Review comment (suggestion):
There's no need for ternary operator here, it reads `error.message` in both cases.

Code after:
  'You attempted to send email to an inactive recipient',
  'New password should be different from the old password',
  'Invalid TOTP code entered',
  'No SSO provider assigned for this domain',
  // Project creation errors
  'The following organization members have reached their maximum limits for the number of active free projects',
  'db_pass must be longer than or equal to 4 characters',
  'There are overdue invoices in the organization(s)',
  'name should not contain a . string',
  'Project creation in the Supabase dashboard is disabled for this Vercel-managed organization.',
  'Your account, which is handled by the Fly Supabase extension, cannot access this endpoint.',
  'already exists in your organization.',
]

/**
 * Captures a critical error to Sentry, filtering out whitelisted errors.
 *
 * @param error - The error object (ResponseError, Error, or any object with a message property)
 * @param context - The context/action that failed (e.g., 'reset password', 'sign up', 'create project')
 *   Attached as the `context` tag on the Sentry event.
 */
export function captureCriticalError(
  error: ResponseError | Error | { message: string },
  context: string
): void {
  if (!error.message) {
    return
  }

  if (error instanceof ResponseError) {
    handleResponseError(error, context)
    return
  }
  if (error instanceof Error) {
    handleError(error, context)
    return
  }

  handleUnknownError(error, context)
}

function handleResponseError(error: ResponseError, context: string) {
  const { code, message, requestPathname } = error
  if (!requestPathname || !code) {
    captureMessage({
      message: `Response Error (no code or requestPathname) w/ message: ${error.message}`,
      context,
    })
    return
  }