/** * Error helpers. * * Keeps telemetry error fields low-sensitivity by using stable labels * (error names) instead of raw exception messages. */ const DEFAULT_ERROR_LABEL = "Error"; const MAX_ERROR_LABEL_LENGTH = 80; export function toSafeErrorLabel(err: unknown): string { if (!(err instanceof Error)) return DEFAULT_ERROR_LABEL; const name = err.name.trim(); if (!name) return DEFAULT_ERROR_LABEL; return name.slice(0, MAX_ERROR_LABEL_LENGTH); } /** Derive outcome from HTTP status code. 500+ is "error", everything else "success". */ export function httpOutcome(statusCode: number): "success" | "error" { return statusCode >= 500 ? "error" : "success"; }