tfl-ts
Version:
🚇 Fully-typed TypeScript client for Transport for London (TfL) API • Zero dependencies • Auto-generated types • Real-time arrivals • Journey planning • Universal compatibility
91 lines (90 loc) • 3.11 kB
TypeScript
/**
* Base error class for TfL API errors
*/
export declare class TflError extends Error {
readonly statusCode?: number | undefined;
readonly originalError?: Error | undefined;
readonly isTflError = true;
readonly timestamp: Date;
readonly requestId?: string;
constructor(message: string, statusCode?: number | undefined, originalError?: Error | undefined, requestId?: string);
}
/**
* HTTP error class for API response errors
*/
export declare class TflHttpError extends TflError {
readonly statusCode: number;
readonly statusText: string;
readonly responseBody?: any | undefined;
readonly url?: string | undefined;
readonly isHttpError = true;
constructor(message: string, statusCode: number, statusText: string, responseBody?: any | undefined, url?: string | undefined, originalError?: Error, requestId?: string);
/**
* Check if this is a client error (4xx)
*/
isClientError(): boolean;
/**
* Check if this is a server error (5xx)
*/
isServerError(): boolean;
/**
* Check if this is an authentication error (401)
*/
isAuthError(): boolean;
/**
* Check if this is a rate limit error (429)
*/
isRateLimitError(): boolean;
}
/**
* Network error class for connection issues
*/
export declare class TflNetworkError extends TflError {
readonly code?: string | undefined;
readonly url?: string | undefined;
readonly isNetworkError = true;
constructor(message: string, code?: string | undefined, url?: string | undefined, originalError?: Error, requestId?: string);
}
/**
* Validation error class for invalid parameters
*/
export declare class TflValidationError extends TflError {
readonly field?: string | undefined;
readonly value?: any | undefined;
readonly isValidationError = true;
constructor(message: string, field?: string | undefined, value?: any | undefined, originalError?: Error, requestId?: string);
}
/**
* Timeout error class for request timeouts
*/
export declare class TflTimeoutError extends TflError {
readonly timeoutMs: number;
readonly url?: string | undefined;
readonly isTimeoutError = true;
constructor(message: string, timeoutMs: number, url?: string | undefined, originalError?: Error, requestId?: string);
}
/**
* Configuration error class for setup issues
*/
export declare class TflConfigError extends TflError {
readonly configField?: string | undefined;
readonly isConfigError = true;
constructor(message: string, configField?: string | undefined, originalError?: Error, requestId?: string);
}
/**
* Error handler utility class
*/
export declare class TflErrorHandler {
/**
* Handle API errors and convert them to appropriate TflError types
*/
static handleApiError(error: any, url?: string, requestId?: string): TflError;
/**
* Check if an error is retryable
*/
static isRetryableError(error: TflError): boolean;
/**
* Get retry delay for an error
*/
static getRetryDelay(error: TflError, attempt: number, baseDelay?: number): number;
}