crawl4ai
Version:
TypeScript SDK for Crawl4AI REST API - Bun & Node.js compatible
97 lines (96 loc) • 2.84 kB
TypeScript
/**
* Custom error classes for Crawl4AI SDK
*/
import type { ValidationError } from './types';
/**
* Base error class for all Crawl4AI errors
*/
export declare class Crawl4AIError extends Error {
status?: number;
statusText?: string;
data?: ValidationError | Record<string, unknown>;
request?: {
url: string;
method: string;
headers?: Record<string, string>;
body?: unknown;
};
constructor(message: string, status?: number, statusText?: string, data?: ValidationError | Record<string, unknown>);
}
/**
* Network-related errors (timeouts, connection failures)
*/
export declare class NetworkError extends Crawl4AIError {
constructor(message: string, cause?: Error);
}
/**
* Request timeout error
*/
export declare class TimeoutError extends NetworkError {
timeout: number;
constructor(timeout: number, url?: string);
}
/**
* Validation errors for request parameters
*/
export declare class RequestValidationError extends Crawl4AIError {
field?: string;
value?: unknown;
constructor(message: string, field?: string, value?: unknown);
}
/**
* Rate limiting error
*/
export declare class RateLimitError extends Crawl4AIError {
retryAfter?: number;
limit?: number;
remaining?: number;
reset?: Date;
constructor(message: string, retryAfter?: number, headers?: Record<string, string>);
}
/**
* Authentication/Authorization errors
*/
export declare class AuthError extends Crawl4AIError {
constructor(message?: string, status?: number);
}
/**
* Server errors (5xx)
*/
export declare class ServerError extends Crawl4AIError {
constructor(message?: string, status?: number, statusText?: string);
}
/**
* Resource not found error
*/
export declare class NotFoundError extends Crawl4AIError {
resource?: string;
constructor(resource?: string);
}
/**
* Response parsing error
*/
export declare class ParseError extends Crawl4AIError {
responseText?: string;
constructor(message: string, responseText?: string);
}
/**
* Type guard to check if an error is a Crawl4AI error
*/
export declare function isCrawl4AIError(error: unknown): error is Crawl4AIError;
/**
* Type guard to check if an error is a rate limit error
*/
export declare function isRateLimitError(error: unknown): error is RateLimitError;
/**
* Type guard to check if an error is an auth error
*/
export declare function isAuthError(error: unknown): error is AuthError;
/**
* Type guard to check if an error is a network error
*/
export declare function isNetworkError(error: unknown): error is NetworkError;
/**
* Helper to create appropriate error based on status code
*/
export declare function createHttpError(status: number, statusText: string, message?: string, data?: unknown, headers?: Record<string, string>): Crawl4AIError;