51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const ERROR_CODES = [
|
|
"UNAUTHENTICATED",
|
|
"AUTH_CONFIG_MISSING",
|
|
"PAYMENT_REQUIRED",
|
|
"INSUFFICIENT_CREDITS",
|
|
"FORBIDDEN",
|
|
"NOT_FOUND",
|
|
"AUDIT_CAPACITY_REACHED",
|
|
"AUDIT_PAGE_LIMIT_EXCEEDED",
|
|
"AUDIT_ALREADY_RUNNING",
|
|
"VALIDATION_ERROR",
|
|
"CRAWL_TARGET_BLOCKED",
|
|
"BACKLINKS_BILLING_ISSUE",
|
|
"AI_SEARCH_BILLING_ISSUE",
|
|
"DATAFORSEO_AUTH_FAILED",
|
|
"RATE_LIMITED",
|
|
"UPSTREAM_UNAVAILABLE",
|
|
"CONFLICT",
|
|
"INTERNAL_ERROR",
|
|
] as const;
|
|
|
|
export const errorCodeSchema = z.enum(ERROR_CODES);
|
|
|
|
export type ErrorCode = z.infer<typeof errorCodeSchema>;
|
|
|
|
const NON_REPORTABLE_ERROR_CODES = new Set<ErrorCode>([
|
|
"UNAUTHENTICATED",
|
|
// External throttling (Google Analytics quota, Autumn, DataForSEO): expected
|
|
// and transient, and nothing in the app can act on it.
|
|
"RATE_LIMITED",
|
|
"NOT_FOUND",
|
|
"PAYMENT_REQUIRED",
|
|
"INSUFFICIENT_CREDITS",
|
|
"VALIDATION_ERROR",
|
|
"AUDIT_CAPACITY_REACHED",
|
|
"AUDIT_PAGE_LIMIT_EXCEEDED",
|
|
"AUDIT_ALREADY_RUNNING",
|
|
]);
|
|
|
|
export function isErrorCode(value: string): value is ErrorCode {
|
|
return errorCodeSchema.safeParse(value).success;
|
|
}
|
|
|
|
export function shouldCaptureAppErrorCode(
|
|
code: ErrorCode | null | undefined,
|
|
): boolean {
|
|
return code == null || !NON_REPORTABLE_ERROR_CODES.has(code);
|
|
}
|