mercadopago
Version:
Mercadopago SDK for Node.js
86 lines (85 loc) • 3.25 kB
TypeScript
/**
* Typed exception hierarchy for MercadoPago API errors.
*
* All exceptions extend {@link MercadoPagoError}, which itself extends {@link Error}.
* Existing code that checks `error.status`, `error.message`, `error.error`, or
* `error.causes` continues to work unchanged.
*
* CWE-209: The `Authorization` header value is never stored in error objects;
* errors are built from the API *response* body, not the outgoing request.
*/
/** Shape of the raw error body returned by the MercadoPago API. */
interface ApiErrorBody {
status?: number;
message?: string;
error?: string;
cause?: unknown[];
[key: string]: unknown;
}
/**
* Base class for all MercadoPago API errors.
*
* Preserves backward-compatible properties (`status`, `message`, `error`, `causes`)
* that existing catch blocks may already reference.
*/
export declare class MercadoPagoError extends Error {
readonly status: number;
readonly error: string;
readonly causes: unknown[];
constructor(body: ApiErrorBody);
}
/** HTTP 400 Bad Request — validation or syntax error. */
export declare class MPBadRequestError extends MercadoPagoError {
}
/** HTTP 401 Unauthorized — missing or invalid credentials. */
export declare class MPAuthenticationError extends MercadoPagoError {
}
/** HTTP 402 Payment Required — transaction processing error (AP/Orders). */
export declare class MPPaymentError extends MercadoPagoError {
}
/** HTTP 403 Forbidden. */
export declare class MPForbiddenError extends MercadoPagoError {
}
/** HTTP 404 Not Found. */
export declare class MPNotFoundError extends MercadoPagoError {
}
/**
* HTTP 409 Conflict — idempotency-key conflict or state-machine conflict.
* Use `MPOrderErrors` constants to distinguish sub-cases via `error.error`.
*/
export declare class MPIdempotencyError extends MercadoPagoError {
}
/** HTTP 422 Unprocessable Entity — business-rule violation. */
export declare class MPValidationError extends MercadoPagoError {
}
/** HTTP 423 Locked — idempotency key temporarily locked (retryable). */
export declare class MPResourceLockedError extends MercadoPagoError {
}
/** HTTP 424 Failed Dependency — internal dependency failure (retryable). */
export declare class MPDependencyError extends MercadoPagoError {
}
/**
* HTTP 429 Too Many Requests.
* Exposes `retryAfter` (seconds) from the `Retry-After` response header.
*/
export declare class MPRateLimitError extends MercadoPagoError {
readonly retryAfter: number | null;
constructor(body: ApiErrorBody, retryAfter?: number | null);
}
/** HTTP 5xx Server Error. */
export declare class MPServerError extends MercadoPagoError {
}
/** Transport-level or network error (timeout, DNS failure, etc.). */
export declare class MPConnectionError extends MercadoPagoError {
constructor(cause: unknown);
private __cause__;
}
/**
* Factory: maps an HTTP status code to the most specific error subtype.
*
* @param status HTTP status code from the API response.
* @param body Parsed API error body.
* @param retryAfter Seconds from the `Retry-After` header (only for 429).
*/
export declare function buildError(status: number, body: ApiErrorBody, retryAfter?: number | null): MercadoPagoError;
export {};