import { RateLimitDetail } from "./rate-limit.schemas.js"; import { PolyesterErrorDetail } from "./error-detail.js"; //#region src/shared/errors.d.ts /** * Typed error hierarchy for the Polyester SDK. * * Every error raised by the SDK extends {@link PolyesterError}, which carries a * stable machine-readable `code` and a `retryable` flag. The tree splits on * retryability so callers can triage with a single `instanceof` check: * * ``` * PolyesterError code retryable * ├── TransientError TRANSIENT_FAILURE true * │ ├── NetworkError NETWORK_ERROR true * │ ├── TimeoutError TIMEOUT true * │ ├── RateLimitError RATE_LIMITED true * │ ├── TimestampSkewError TIMESTAMP_SKEW true * │ │ └── RequestDeadlineExceededError REQUEST_DEADLINE_EXCEEDED * │ ├── ServiceUnavailableError SERVICE_UNAVAILABLE true * │ └── ClaimOutcomeUnknownError CLAIM_OUTCOME_UNKNOWN true * ├── RequestError REQUEST_FAILED false * │ ├── ValidationError VALIDATION_FAILED false * │ │ ├── StaleQuoteError STALE_QUOTE * │ │ ├── WithdrawDeadlineExpiredError WITHDRAW_DEADLINE_EXPIRED * │ │ └── PolicyScopeMismatchError POLICY_SCOPE_MISMATCH * │ ├── ResourceNotFoundError RESOURCE_NOT_FOUND false * │ ├── RequestTooLargeError REQUEST_TOO_LARGE false * │ ├── NotImplementedError NOT_IMPLEMENTED false * │ ├── AlreadyExistsError ALREADY_EXISTS false * │ │ └── UserOperationAlreadyKnownError USER_OPERATION_ALREADY_KNOWN * │ ├── PermissionError PERMISSION_DENIED false * │ ├── AuthenticationError UNAUTHENTICATED false * │ ├── PreconditionFailedError PRECONDITION_FAILED false * │ │ ├── RevisionConflictError REVISION_CONFLICT * │ │ ├── PolicyInUseError POLICY_IN_USE * │ │ ├── PolicyLockedError POLICY_LOCKED * │ │ ├── SubaccountChallengeInvalidError SUBACCOUNT_CHALLENGE_INVALID * │ │ └── MfaLastFactorRequiredError MFA_LAST_FACTOR_REQUIRED * │ ├── ConfigurationError INVALID_CONFIGURATION false * │ ├── MfaRequiredError MFA_REQUIRED false * │ │ ├── MfaEnrollmentRequiredError MFA_ENROLLMENT_REQUIRED * │ │ ├── StepUpRequiredError STEP_UP_REQUIRED * │ │ └── SessionElevationRequiredError SESSION_ELEVATION_REQUIRED * │ ├── MfaVerificationError MFA_VERIFICATION_FAILED false * │ ├── UserOperationSendTimeoutError USER_OPERATION_SEND_TIMEOUT false * │ ├── OutcomeUnknownError OUTCOME_UNKNOWN false * │ └── UserOperationNotExecutedError USER_OPERATION_NOT_EXECUTED false * ├── InternalServerError INTERNAL_SERVER_ERROR false * └── RealtimeError REALTIME_ERROR varies * ``` * * Catalog errors (`CatalogLookupError`, `CatalogConversionError`, …) plug into * the same tree under `RequestError`/`ValidationError`. * * Errors mapped from RPC failures keep the original `ConnectError` as `cause` * and carry the response's `status` when available. * * @example * ```ts * try { * await client.orders.createSpotOrder(input); * } catch (err) { * if (err instanceof RateLimitError) await sleep(err.retryAfterMs ?? 1000); * else if (err instanceof TransientError) retry(); * else if (err instanceof StepUpRequiredError) promptForMfa(); * else throw err; * } * ``` */ /** Stable machine-readable codes carried by built-in SDK errors. */ type PolyesterErrorCode = "TRANSIENT_FAILURE" | "NETWORK_ERROR" | "TIMEOUT" | "RATE_LIMITED" | "TIMESTAMP_SKEW" | "REQUEST_DEADLINE_EXCEEDED" | "SERVICE_UNAVAILABLE" | "CLAIM_OUTCOME_UNKNOWN" | "REQUEST_FAILED" | "VALIDATION_FAILED" | "STALE_QUOTE" | "WITHDRAW_DEADLINE_EXPIRED" | "RESOURCE_NOT_FOUND" | "REQUEST_TOO_LARGE" | "NOT_IMPLEMENTED" | "ALREADY_EXISTS" | "USER_OPERATION_ALREADY_KNOWN" | "USER_OPERATION_SEND_TIMEOUT" | "OUTCOME_UNKNOWN" | "USER_OPERATION_NOT_EXECUTED" | "PERMISSION_DENIED" | "UNAUTHENTICATED" | "PRECONDITION_FAILED" | "REVISION_CONFLICT" | "SUBACCOUNT_CHALLENGE_INVALID" | "POLICY_IN_USE" | "POLICY_LOCKED" | "POLICY_SCOPE_MISMATCH" | "INVALID_CONFIGURATION" | "MFA_REQUIRED" | "MFA_ENROLLMENT_REQUIRED" | "STEP_UP_REQUIRED" | "SESSION_ELEVATION_REQUIRED" | "MFA_LAST_FACTOR_REQUIRED" | "MFA_VERIFICATION_FAILED" | "INTERNAL_SERVER_ERROR" | "REALTIME_ERROR" | "CATALOG_LOOKUP_MISS" | "CATALOG_NOT_READY" | "CATALOG_CONVERSION_INVALID" | "CATALOG_VALIDATION_FAILED"; interface PolyesterErrorOptions { /** Underlying error, typically the original `ConnectError` for RPC failures. */ cause?: unknown; /** Recognized structured backend rejection, decoded at the RPC boundary. */ detail?: PolyesterErrorDetail; /** HTTP status of the failed response. */ status?: number; } declare function normalizeErrorMessage(message: string): string; /** * Base class for every error raised by the Polyester SDK. * * Check `retryable` (or `instanceof TransientError`) to decide whether the * same call can be safely retried, and switch on `code` for exhaustive, * minification-safe handling. */ declare abstract class PolyesterError extends Error { /** Stable machine-readable error code, e.g. `"RATE_LIMITED"`. */ abstract readonly code: string; /** Whether retrying the same operation may succeed. */ abstract readonly retryable: boolean; readonly detail: PolyesterErrorDetail | undefined; /** * HTTP status of the failed response. For Connect errors that carry no raw * HTTP status, the Connect protocol's status for the error code. */ readonly status: number | undefined; constructor(message: string, options?: PolyesterErrorOptions); } /** * A transient failure — the request may never have reached the backend or the * backend was temporarily unable to serve it. Follow the operation's retry * contract: reuse requestId for idempotent mutations. For single-order creation, * reconcile by clientOrderId; reusing it returns a conflict rather than replay. */ declare class TransientError extends PolyesterError { readonly code: string; readonly retryable = true; constructor(message: string, options?: PolyesterErrorOptions); } /** The request could not be sent or the connection failed mid-flight. */ declare class NetworkError extends TransientError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The request timed out before the backend produced a response. */ declare class TimeoutError extends TransientError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } interface RateLimitErrorOptions extends PolyesterErrorOptions { /** Suggested wait before retrying, when the backend provided one. */ retryAfterMs?: number; /** Structured quota state attached to the rejection, when provided. */ rateLimit?: RateLimitDetail; } /** The backend rejected the request due to rate limiting. */ declare class RateLimitError extends TransientError { readonly code: string; /** Suggested wait before retrying, in milliseconds, when known. */ readonly retryAfterMs?: number; /** Structured quota state attached to the rejection, when provided. */ readonly rateLimit?: RateLimitDetail; constructor(message: string, options?: RateLimitErrorOptions); } /** * The API-key signature timestamp fell outside the backend's skew window, e.g. * because the request waited too long in the runtime's fetch queue during a * large concurrent burst, or the local clock drifted. Retrying the call signs * it again with a fresh timestamp; bound concurrency if it recurs. */ declare class TimestampSkewError extends TransientError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** * A signed order or trigger write passed authentication, but its receive window * (`X-API-TIMESTAMP` plus `recvWindow`) ended before it was sent on for admission. * Nothing changed and it is never an unknown outcome, so retrying the call, which * signs it again with a fresh timestamp, is safe. */ declare class RequestDeadlineExceededError extends TimestampSkewError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The backend is temporarily unavailable (e.g. overloaded or restarting). */ declare class ServiceUnavailableError extends TransientError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } interface ClaimOutcomeUnknownErrorOptions extends PolyesterErrorOptions { /** Claim the error concerns, when the backend named it. */ claimId?: string; } /** * Today's daily claim is recorded and its payout was submitted, but its result could not be * confirmed. Treat it as a pending claim, not a failure: the claim is never paid twice, so poll * `claims.getDailyClaimStatus` until `claimId` matches and the claim is `claimed`, or retry * `claims.claimDailyReward` to get its current state. */ declare class ClaimOutcomeUnknownError extends TransientError { readonly code: string; /** Claim the error concerns, when the backend named it. */ readonly claimId: string | undefined; constructor(message: string, options?: ClaimOutcomeUnknownErrorOptions); } /** * The request itself was rejected — retrying the identical call will fail the * same way. Fix the input, authentication, or permissions first. */ declare class RequestError extends PolyesterError { readonly code: string; readonly retryable = false; constructor(message: string, options?: PolyesterErrorOptions); } /** The request input failed validation (client- or server-side). */ declare class ValidationError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The submitted client reference quote exceeded the market's configured drift limit. */ declare class StaleQuoteError extends ValidationError { readonly code: "STALE_QUOTE"; constructor(message: string, options?: PolyesterErrorOptions); } /** * The prepared withdraw's signed deadline has passed, so the backend would * reject it. Prepare (and sign) the withdraw again. * * Thrown by `submit` before sending once the deadline has passed, and when the * backend rejects the deadline as expired: one that lapsed in flight, or one * signed from a device clock running behind the server's. */ declare class WithdrawDeadlineExpiredError extends ValidationError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** * The request body was over the endpoint's size limit (HTTP 413). The limit is * fixed per endpoint, so the same request fails again; send a smaller one. */ declare class RequestTooLargeError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The requested resource does not exist (or is not visible to the caller). */ declare class ResourceNotFoundError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The backend does not implement the requested operation (HTTP 501 / Connect `unimplemented`). */ declare class NotImplementedError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The resource already exists (e.g. a duplicate `clientOrderId`). */ declare class AlreadyExistsError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** * The bundler already holds this exact UserOperation (it answered "Already * known"), so the earlier submission is still pending. Wait on `userOpHash` * instead of signing again; a new operation would execute a second time. */ declare class UserOperationAlreadyKnownError extends AlreadyExistsError { readonly code: string; readonly userOpHash: `0x${string}`; constructor(message: string, userOpHash: `0x${string}`, options?: PolyesterErrorOptions); } /** * `eth_sendUserOperation` timed out after the UserOperation was signed. The * bundler may still have accepted it, so the outcome is unknown rather than * rejected. Wait on `userOpHash` instead of signing again; a new operation * could execute a second time. Not retryable for the same reason. */ declare class UserOperationSendTimeoutError extends RequestError { readonly code: string; readonly userOpHash: `0x${string}`; constructor(message: string, userOpHash: `0x${string}`, options?: PolyesterErrorOptions); } /** * An order or trigger change was sent but not confirmed in time, so it may * still apply. Not retryable: read the order by its client order ID, or list * triggers by client trigger ID, before sending it again. `detail.code` names * the operation, e.g. `ORDER_CREATE_OUTCOME_UNKNOWN`. */ declare class OutcomeUnknownError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The caller is authenticated but not allowed to perform this operation. */ declare class PermissionError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The caller is not authenticated (missing, expired, or invalid credentials). */ declare class AuthenticationError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The system is not in a state that allows this operation (e.g. insufficient balance). */ declare class PreconditionFailedError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** * The resource changed after it was read, so the submitted expected revision * is stale. Refetch and let the caller reconcile; do not blindly retry. */ declare class RevisionConflictError extends PreconditionFailedError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** * The subaccount authorization is expired, replaced by a newer challenge, already * consumed, or has an invalid signature. Request a fresh challenge via * `subaccounts.createChallenge`. Temporary verification failures surface as * `ServiceUnavailableError` instead; retry those with the same signed challenge. */ declare class SubaccountChallengeInvalidError extends PreconditionFailedError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The policy cannot be removed while accounts or API keys still use it. */ declare class PolicyInUseError extends PreconditionFailedError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The policy is locked against the requested mutation. */ declare class PolicyLockedError extends PreconditionFailedError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The policy does not belong to the account scope targeted by the request. */ declare class PolicyScopeMismatchError extends ValidationError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The SDK was configured incorrectly (bad environment, missing credentials, …). */ declare class ConfigurationError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** * The operation requires additional multi-factor authentication. Catch this * class to handle all MFA flows, or the subclasses to branch per flow. */ declare class MfaRequiredError extends RequestError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The user must enroll in MFA before this operation can proceed. */ declare class MfaEnrollmentRequiredError extends MfaRequiredError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The operation requires a fresh MFA step-up proof (retry with `X-Auth-Step-Up`). */ declare class StepUpRequiredError extends MfaRequiredError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The operation requires a recent MFA-elevated session, not a one-use step-up proof. */ declare class SessionElevationRequiredError extends MfaRequiredError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The requested deletion would leave the account without an active MFA factor. */ declare class MfaLastFactorRequiredError extends PreconditionFailedError { readonly code: string; constructor(message: string, options?: PolyesterErrorOptions); } /** The reason an MFA challenge could not be completed. */ type MfaVerificationFailureReason = "challenge-invalid" | "challenge-locked" | "otp-invalid" | "recovery-code-invalid" | "passkey-invalid"; /** * An expected MFA verification rejection. Callers should select their own * user-facing copy from `reason` instead of displaying the backend message. */ declare class MfaVerificationError extends RequestError { readonly reason: MfaVerificationFailureReason; readonly code: string; constructor(message: string, reason: MfaVerificationFailureReason, options?: PolyesterErrorOptions); } /** * The backend failed unexpectedly or returned a malformed response. Not * automatically retryable — the failure may recur and mutations may have * partially applied. */ declare class InternalServerError extends PolyesterError { readonly code: string; readonly retryable = false; constructor(message: string, options?: PolyesterErrorOptions); } interface RealtimeErrorOptions extends PolyesterErrorOptions { /** Centrifugo protocol, disconnect, or unsubscribe code; 0 when none applies. */ realtimeCode?: number; /** True when the realtime client is already retrying on its own. */ retryable?: boolean; } /** * A realtime subscription failure reported by the server or the websocket * client. `retryable` errors (e.g. code 109, token expired) are being retried * automatically; only non-retryable ones end the subscription. */ declare class RealtimeError extends PolyesterError { readonly code: "REALTIME_ERROR"; readonly retryable: boolean; readonly realtimeCode: number; constructor(message: string, options?: RealtimeErrorOptions); } /** * Checks whether an error represents an aborted request (caller-initiated via * `AbortSignal`). Aborts are intentionally NOT part of the {@link PolyesterError} * tree and are never retryable. */ declare function isAbortError(err: unknown): boolean; /** Checks whether an error is the `TimeoutError` raised by `AbortSignal.timeout()`. */ declare function isTimeoutAbortError(err: unknown): boolean; /** * Checks whether an error is the `TypeError` a browser `fetch` raises when the * connection drops, either on the request or while reading the response body. */ declare function isFetchNetworkError(err: unknown): boolean; /** Maps a plain HTTP status code onto the SDK error tree. */ declare function errorFromHttpStatus(status: number, message: string, options?: RateLimitErrorOptions): PolyesterError; /** * The bundler reported a UserOperation as definitively not executed, so nothing * moved on chain: `rejected` (dropped by the bundler, often for a fee below the * current price) or `failed` (its bundle transaction reverted). Submitting a * fresh operation is safe. */ declare class UserOperationNotExecutedError extends RequestError { readonly code: string; readonly userOpHash: `0x${string}`; /** The bundler's `pimlico_getUserOperationStatus` result. */ readonly bundlerStatus: "rejected" | "failed"; constructor(message: string, userOpHash: `0x${string}`, bundlerStatus: "rejected" | "failed", options?: PolyesterErrorOptions); } //#endregion export { AlreadyExistsError, AuthenticationError, ClaimOutcomeUnknownError, ClaimOutcomeUnknownErrorOptions, ConfigurationError, InternalServerError, MfaEnrollmentRequiredError, MfaLastFactorRequiredError, MfaRequiredError, MfaVerificationError, MfaVerificationFailureReason, NetworkError, NotImplementedError, OutcomeUnknownError, PermissionError, PolicyInUseError, PolicyLockedError, PolicyScopeMismatchError, PolyesterError, PolyesterErrorCode, type PolyesterErrorDetail, PolyesterErrorOptions, PreconditionFailedError, RateLimitError, RateLimitErrorOptions, RealtimeError, RealtimeErrorOptions, RequestDeadlineExceededError, RequestError, RequestTooLargeError, ResourceNotFoundError, RevisionConflictError, ServiceUnavailableError, SessionElevationRequiredError, StaleQuoteError, StepUpRequiredError, SubaccountChallengeInvalidError, TimeoutError, TimestampSkewError, TransientError, UserOperationAlreadyKnownError, UserOperationNotExecutedError, UserOperationSendTimeoutError, ValidationError, WithdrawDeadlineExpiredError, errorFromHttpStatus, isAbortError, isFetchNetworkError, isTimeoutAbortError, normalizeErrorMessage }; //# sourceMappingURL=errors.d.ts.map