import { closedErrorType, fetchErrorType, argumentErrorType, limiterErrorType, limitExceededErrorType, multiErrorType, queueOverflowErrorType } from "./constant.js"; import { RateLimiterAbstract, RateLimiterQueue } from "rate-limiter-flexible"; import { RateLimiterQueueError } from "rate-limiter-flexible/lib/component/index.js"; /** Base interface for all errors returned by `motion-sdk`. * * @public */ export interface MotionError { /** Indicates the class of the error. * * @remarks * Each distinct type of {@link MotionError} has its own constant value * of `errorType`. This is the recommended way to programmatically * distinguish between, say, a {@link LimiterError} and a {@link FetchError}, * to take appropriate recovery steps. * * See {@link isMotionError} and the related `is*Error` functions for * built-in type assertions. * */ readonly errorType: typeof argumentErrorType | typeof fetchErrorType | typeof limiterErrorType | typeof queueOverflowErrorType | typeof closedErrorType | typeof limitExceededErrorType | typeof multiErrorType; /** Developer-readable error message. */ readonly message: string; } /** {@inheritDoc argumentErrorType} * * @public * */ export declare class ArgumentError extends Error implements MotionError { /** Name of the invalid argument. */ readonly argumentName: string; /** Value of the invalid argument. */ readonly argumentValue: T; /** {@inheritDoc MotionError.message} */ readonly message: string; /** {@inheritDoc MotionError.errorType} */ errorType: typeof argumentErrorType; constructor( /** Name of the invalid argument. */ argumentName: string, /** Value of the invalid argument. */ argumentValue: T, /** {@inheritDoc MotionError.message} */ message: string); } /** {@inheritDoc fetchErrorType} * * @public */ export declare class FetchError extends Error implements MotionError { /** The underlying error that was thrown by {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | fetch}. */ readonly cause: unknown; /** The failing parameters to {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | fetch}. */ readonly request: { input: string | URL | globalThis.Request; init?: RequestInit; }; /** {@inheritDoc MotionError.errorType} */ readonly errorType: typeof fetchErrorType; constructor( /** The underlying error that was thrown by {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | fetch}. */ cause: unknown, /** The failing parameters to {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | fetch}. */ request: { input: string | URL | globalThis.Request; init?: RequestInit; }); } /** {@inheritDoc closedErrorType} * * @public */ export declare class ClosedError extends Error implements MotionError { /** Developer-readable reason for the closure. */ readonly reason: string; /** Error that caused the closure. */ readonly cause?: MotionError | undefined; /** {@inheritDoc MotionError.errorType} */ readonly errorType: typeof closedErrorType; constructor( /** Developer-readable reason for the closure. */ reason: string, /** Error that caused the closure. */ cause?: MotionError | undefined); } /** {@inheritDoc limitExceededErrorType} * * @public */ export declare class LimitExceededError extends Error implements MotionError { /** {@link https://developer.mozilla.org/en-US/docs/Web/API/Response | Response} that was returned by Motion. */ readonly response: Response; /** {@inheritDoc MotionError.errorType} */ errorType: typeof limitExceededErrorType; constructor( /** {@link https://developer.mozilla.org/en-US/docs/Web/API/Response | Response} that was returned by Motion. */ response: Response); } /** {@inheritDoc multiErrorType} * * @public */ export declare class MultiError extends Error implements MotionError { /** The underlying errors. */ readonly errors: T[]; /** {@inheritDoc MotionError.errorType} */ readonly errorType: typeof multiErrorType; constructor( /** The underlying errors. */ errors: T[]); } /** {@inheritDoc limiterErrorType} * * @public */ export declare class LimiterError extends Error implements MotionError { /** The erroring rate limiter. See {@link https://github.com/animir/node-rate-limiter-flexible/wiki | rate-limiter-abstract reference}. * */ readonly limiter: RateLimiterAbstract; /** The underlying error from the rate limiter. */ readonly cause: unknown; /** The rate limiter key that was attempted. * * @remarks * An {@link https://github.com/animir/node-rate-limiter-flexible/wiki | rate-limiter-flexible} * tracks the same limit independently across multiple keys. In some * cases it is important to know which particular key is returning * errors. * */ readonly attemptedKey?: string | number | undefined; /** {@inheritDoc MotionError.errorType} */ errorType: typeof limiterErrorType; constructor( /** The erroring rate limiter. See {@link https://github.com/animir/node-rate-limiter-flexible/wiki | rate-limiter-abstract reference}. * */ limiter: RateLimiterAbstract, /** The underlying error from the rate limiter. */ cause: unknown, /** The rate limiter key that was attempted. * * @remarks * An {@link https://github.com/animir/node-rate-limiter-flexible/wiki | rate-limiter-flexible} * tracks the same limit independently across multiple keys. In some * cases it is important to know which particular key is returning * errors. * */ attemptedKey?: string | number | undefined); } /** {@inheritDoc queueOverflowErrorType } * * @public * */ export declare class QueueOverflowError extends Error implements MotionError { /** The overflowing queue. */ readonly queue: RateLimiterQueue; /** The overflow error from the underlying framework. */ readonly cause: RateLimiterQueueError; /** The rate limiter key that was attempted. */ readonly attemptedKey: string | number; /** {@inheritDoc MotionError.errorType} */ errorType: typeof queueOverflowErrorType; constructor( /** The overflowing queue. */ queue: RateLimiterQueue, /** The overflow error from the underlying framework. */ cause: RateLimiterQueueError, /** The rate limiter key that was attempted. */ attemptedKey: string | number); } /** Type assertion for {@link MotionError}. * * @public */ export declare function isMotionError(o: unknown): o is MotionError; /** Type assertion for {@link ArgumentError}. * * @public */ export declare function isArgumentError(o: unknown): o is ArgumentError; /** Type assertion for {@link FetchError}. * * @public */ export declare function isFetchError(o: unknown): o is FetchError; /** Type assertion for {@link ClosedError}. * * @public */ export declare function isClosedError(o: unknown): o is ClosedError; /** Type assertion for {@link LimitExceededError}. * * @public */ export declare function isLimitExceededError(o: unknown): o is LimitExceededError; /** Type assertion for {@link MultiError}. * * @public */ export declare function isMultiError(o: unknown): o is MultiError; /** Type assertion for {@link LimiterError}. * * @public */ export declare function isLimiterError(o: unknown): o is LimiterError; /** Type assertion for {@link QueueOverflowError}. * * @public */ export declare function isQueueOverflowError(o: unknown): o is QueueOverflowError; /** Possible single errors returned by {@link Motion.unsafe_fetch}. * * @public */ export type UnsafeFetchIndividualError = ArgumentError | LimitExceededError | FetchError; /** Possible errors returned by {@link Motion.unsafe_fetch}. * * @public */ export type UnsafeFetchError = UnsafeFetchIndividualError | MultiError; /** Possible single errors returned by {@link Motion.fetch}. * * @public */ export type FetchIndividualError = UnsafeFetchIndividualError | ClosedError | LimiterError | QueueOverflowError; /** Possible errors returned by {@link Motion.fetch}. * * @public */ export type MotionFetchError = FetchIndividualError | MultiError; //# sourceMappingURL=error.d.ts.map