describeBillingBlock (errors/billing.ts)

sushi-saas-template · src/lib/errors/billing.ts · typescript · MIT
payments

Classifies billing-related API errors into structured blocks (credits, feature, limit) with validated numeric details.

// Source: https://github.com/PansaLegrand/sushi-saas-template | License: MIT | Copyright 2025 Pan Wenzhu
// Provided via justclaw.it.com; keep this notice with the code.
import type { ErrorCode } from "./catalog";
import { isClientApiError } from "./client";

/**
 * The seam between "the server refused" and "here is what to do about it".
 *
 * Three catalog codes mean the same thing to a user — *you cannot do this until
 * you pay for something* — and differ only in what they should be offered. This
 * module is the one place that knows which codes those are, so a page's catch
 * block never grows its own list. Add a fourth code here and every surface that
 * uses `useBillingPrompt` picks it up.
 *
 * It reads `details` off the wire and nothing else. The numbers and the tier
 * name are t

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key