@vepler/http-client
Version:
A flexible and extensible API service library for making HTTP requests with built-in authentication support for bearer tokens and API keys.
127 lines (126 loc) • 3.9 kB
TypeScript
import { AxiosResponse, AxiosError } from 'axios';
/**
* Base HTTP error class for all API errors
*/
export declare class HttpError extends Error {
status: number;
statusText: string;
endpoint: string;
method: string;
url: string;
data: any;
isHttpError: boolean;
constructor(message: string, status?: number, statusText?: string, endpoint?: string, method?: string, url?: string, data?: any);
/**
* Formats the error for developer debugging
*/
toJSON(): {
name: string;
message: string;
status: number;
statusText: string;
endpoint: string;
method: string;
url: string;
data: any;
};
/**
* Creates an HttpError from an AxiosError
*/
static fromAxiosError(error: AxiosError): HttpError;
}
/**
* 400-499 level HTTP errors
*/
export declare class ClientError extends HttpError {
constructor(message: string, status?: number, statusText?: string, endpoint?: string, method?: string, url?: string, data?: any);
}
/**
* 500-599 level HTTP errors
*/
export declare class ServerError extends HttpError {
constructor(message: string, status?: number, statusText?: string, endpoint?: string, method?: string, url?: string, data?: any);
}
/**
* Network or connectivity errors
*/
export declare class NetworkError extends HttpError {
request: any;
constructor(message: string, request?: any, endpoint?: string, method?: string, url?: string);
toJSON(): {
request: string | null;
name: string;
message: string;
status: number;
statusText: string;
endpoint: string;
method: string;
url: string;
data: any;
};
}
/**
* Authentication errors (401, 403)
*/
export declare class AuthError extends ClientError {
credentials: Record<string, string>;
constructor(message: string, status?: number, statusText?: string, endpoint?: string, method?: string, url?: string, data?: any, credentials?: Record<string, string>);
static sanitizeCredentials(credentials: Record<string, string>): Record<string, string>;
toJSON(): {
credentials: Record<string, string>;
name: string;
message: string;
status: number;
statusText: string;
endpoint: string;
method: string;
url: string;
data: any;
};
}
/**
* Request timeout errors
*/
export declare class TimeoutError extends NetworkError {
constructor(message?: string, request?: any, endpoint?: string, method?: string, url?: string);
}
/**
* Rate limiting errors
*/
export declare class RateLimitError extends ClientError {
retryAfter?: number;
constructor(message: string, retryAfter?: number, status?: number, statusText?: string, endpoint?: string, method?: string, url?: string, data?: any);
toJSON(): {
retryAfter: number | undefined;
name: string;
message: string;
status: number;
statusText: string;
endpoint: string;
method: string;
url: string;
data: any;
};
}
/**
* Validation errors (400 with specific validation failures)
*/
export declare class ValidationError extends ClientError {
validationErrors: Record<string, string[]>;
constructor(message: string, validationErrors?: Record<string, string[]>, status?: number, statusText?: string, endpoint?: string, method?: string, url?: string, data?: any);
toJSON(): {
validationErrors: Record<string, string[]>;
name: string;
message: string;
status: number;
statusText: string;
endpoint: string;
method: string;
url: string;
data: any;
};
}
/**
* Creates the appropriate error type based on HTTP status code
*/
export declare function createErrorFromResponse(response: AxiosResponse): HttpError;