observation-js
Version:
A fully-typed TypeScript client for the waarneming.nl API.
45 lines (44 loc) • 1.52 kB
TypeScript
/**
* Base class for all errors thrown by the observation-js library.
*/
export declare class ObservationError extends Error {
constructor(message: string);
}
/**
* Represents an error returned by the Waarneming.nl API.
*/
export declare class ApiError extends ObservationError {
readonly response: Response | null;
readonly body: unknown;
constructor(message: string, response: Response | null, body: unknown);
}
/**
* Represents an authentication-related error (e.g., 401 Unauthorized, 403 Forbidden).
*/
export declare class AuthenticationError extends ApiError {
constructor(response: Response, body: unknown);
}
/**
* Represents a rate limiting error (429 Too Many Requests).
* Contains information about retry timing if available.
*/
export declare class RateLimitError extends ApiError {
readonly retryAfter?: number;
readonly resetTime?: Date;
constructor(response: Response, body: unknown);
/**
* Get the recommended delay in milliseconds before retrying
*/
getRetryDelayMs(): number;
/**
* Check if enough time has passed since the rate limit was hit to retry
*/
canRetryNow(): boolean;
}
/**
* Utility function to handle rate limiting with automatic retry
* @param operation - The operation to retry
* @param maxRetries - Maximum number of retries (default: 3)
* @returns Promise that resolves with the operation result
*/
export declare function withRateLimitRetry<T>(operation: () => Promise<T>, maxRetries?: number): Promise<T>;