fix: suppress alerts for expected billing errors in increment-usage task (#27535)
- Skip retrying and alerting for temp/sandbox subscription IDs - Skip retrying and alerting for non-usage-based subscriptions - Log expected errors at info level instead of error level Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
52f3ddaf74
commit
336295c0ab
@@ -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<typeof INCREMENT_USAGE_JOB_ID, typeof platformBillingTaskSchema> =
|
||||
schemaTask({
|
||||
id: INCREMENT_USAGE_JOB_ID,
|
||||
@@ -19,6 +43,11 @@ export const incrementUsage: TaskWithSchema<typeof INCREMENT_USAGE_JOB_ID, typeo
|
||||
try {
|
||||
await billingTaskService.incrementUsage(payload);
|
||||
} catch (error) {
|
||||
if (isExpectedBillingError(error)) {
|
||||
logger.info("Skipping expected billing error", { error: (error as Error).message });
|
||||
return;
|
||||
}
|
||||
|
||||
if (error instanceof Error || error instanceof ErrorWithCode) logger.error(error.message);
|
||||
else logger.error("Unknown error in incrementUsage", { error });
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user