diff --git a/packages/features/ee/organizations/lib/billing/tasker/trigger/increment-usage.ts b/packages/features/ee/organizations/lib/billing/tasker/trigger/increment-usage.ts index 9101925d16..f7abc9641a 100644 --- a/packages/features/ee/organizations/lib/billing/tasker/trigger/increment-usage.ts +++ b/packages/features/ee/organizations/lib/billing/tasker/trigger/increment-usage.ts @@ -5,6 +5,30 @@ import { INCREMENT_USAGE_JOB_ID } from "../constants"; import { platformBillingTaskConfig } from "./config"; import { platformBillingTaskSchema } from "./schema"; +/** + * Checks if an error is expected and should not trigger alerts. + * Expected errors include: + * - Subscriptions with "temp" or "sandbox" in the ID (test/placeholder subscriptions) + * - Subscriptions that are not usage-based (this task only handles usage-based subscriptions) + */ +function isExpectedBillingError(error: unknown): boolean { + if (!(error instanceof Error)) return false; + + const message = error.message.toLowerCase(); + + // Check for temp/sandbox subscription IDs in "No such subscription" errors + if (message.includes("no such subscription")) { + return message.includes("temp") || message.includes("sandbox"); + } + + // Check for non-usage-based subscription errors + if (message.includes("is not usage based")) { + return true; + } + + return false; +} + export const incrementUsage: TaskWithSchema = schemaTask({ id: INCREMENT_USAGE_JOB_ID, @@ -19,6 +43,11 @@ export const incrementUsage: TaskWithSchema