UNPKG

splitwise

Version:

A TypeScript SDK for the Splitwise API.

82 lines 3.76 kB
/** * Typed error hierarchy for the Splitwise SDK, following the Stripe pattern. * * SplitwiseError (base) * ├── SplitwiseApiError (HTTP errors from the API) * │ ├── SplitwiseAuthenticationError (401) * │ ├── SplitwiseForbiddenError (403) * │ ├── SplitwiseNotFoundError (404) * │ ├── SplitwiseValidationError (400) * │ ├── SplitwiseRateLimitError (429) * │ ├── SplitwiseServerError (5xx) * │ └── SplitwiseConstraintError (200 with success:false / non-empty errors) * └── SplitwiseConnectionError (network failures) */ export declare class SplitwiseError extends Error { constructor(message: string); } export declare class SplitwiseApiError extends SplitwiseError { readonly statusCode: number; readonly code: string; readonly raw: unknown; constructor(statusCode: number, message: string, code: string, raw: unknown); } export declare class SplitwiseAuthenticationError extends SplitwiseApiError { constructor(message: string, code: string, raw: unknown); } export declare class SplitwiseForbiddenError extends SplitwiseApiError { constructor(message: string, code: string, raw: unknown); } export declare class SplitwiseNotFoundError extends SplitwiseApiError { constructor(message: string, code: string, raw: unknown); } export declare class SplitwiseValidationError extends SplitwiseApiError { constructor(message: string, code: string, raw: unknown); } export declare class SplitwiseRateLimitError extends SplitwiseApiError { /** * Server-suggested wait time in seconds, parsed from the Retry-After * header. Handles both delta-seconds (e.g. "120") and HTTP-date formats. * Undefined when the server didn't send the header or it was malformed. */ readonly retryAfter: number | undefined; constructor(message: string, code: string, raw: unknown, retryAfter?: number); } export declare class SplitwiseServerError extends SplitwiseApiError { constructor(statusCode: number, message: string, code: string, raw: unknown); } /** * Splitwise's "destructive" endpoints (delete_*, undelete_*, add_user_to_group, * remove_user_from_group) and some create/update endpoints can return HTTP 200 * with `success: false` or a non-empty `errors` field when the operation * couldn't complete for a domain reason (e.g. trying to delete a friend with a * non-zero balance). The SDK surfaces these as a typed exception following the * Stripe model -- failures are always thrown, never returned as data. */ export declare class SplitwiseConstraintError extends SplitwiseApiError { constructor(message: string, code: string, raw: unknown); } export declare class SplitwiseConnectionError extends SplitwiseError { readonly cause: Error | undefined; constructor(message: string, cause?: Error); } /** Minimal interface so we don't depend on the DOM `Headers` type at compile time. */ interface HeadersLike { get(name: string): string | null; } /** * Parse a Retry-After header value, returning the delay in seconds. * * Per RFC 7231 § 7.1.3 the value can be either: * - a non-negative integer (delta-seconds), e.g. "120" * - an HTTP-date, e.g. "Wed, 21 Oct 2026 07:28:00 GMT" * * Returns undefined if the value is missing, malformed, or in the past. */ export declare function parseRetryAfter(raw: string | null | undefined, now?: () => number): number | undefined; /** * Maps an HTTP status code to the appropriate SplitwiseApiError subclass. */ export declare function createApiError(statusCode: number, message: string, code: string, raw: unknown, headers?: HeadersLike): SplitwiseApiError; export {}; //# sourceMappingURL=errors.d.ts.map