UNPKG

2.96 kBTypeScriptView Raw
1import type { Timings } from '@szmarczak/http-timer';
2import type Options from './options.js';
3import type { TimeoutError as TimedOutTimeoutError } from './timed-out.js';
4import type { PlainResponse, Response } from './response.js';
5import type Request from './index.js';
6type Error = NodeJS.ErrnoException;
7/**
8An error to be thrown when a request fails.
9Contains a `code` property with error class code, like `ECONNREFUSED`.
10*/
11export declare class RequestError<T = unknown> extends Error {
12 input?: string;
13 code: string;
14 stack: string;
15 readonly options: Options;
16 readonly response?: Response<T>;
17 readonly request?: Request;
18 readonly timings?: Timings;
19 constructor(message: string, error: Partial<Error & {
20 code?: string;
21 }>, self: Request | Options);
22}
23/**
24An error to be thrown when the server redirects you more than ten times.
25Includes a `response` property.
26*/
27export declare class MaxRedirectsError extends RequestError {
28 readonly response: Response;
29 readonly request: Request;
30 readonly timings: Timings;
31 constructor(request: Request);
32}
33/**
34An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
35Includes a `response` property.
36*/
37export declare class HTTPError<T = any> extends RequestError<T> {
38 readonly response: Response<T>;
39 readonly request: Request;
40 readonly timings: Timings;
41 constructor(response: PlainResponse);
42}
43/**
44An error to be thrown when a cache method fails.
45For example, if the database goes down or there's a filesystem error.
46*/
47export declare class CacheError extends RequestError {
48 readonly request: Request;
49 constructor(error: Error, request: Request);
50}
51/**
52An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
53*/
54export declare class UploadError extends RequestError {
55 readonly request: Request;
56 constructor(error: Error, request: Request);
57}
58/**
59An error to be thrown when the request is aborted due to a timeout.
60Includes an `event` and `timings` property.
61*/
62export declare class TimeoutError extends RequestError {
63 readonly request: Request;
64 readonly timings: Timings;
65 readonly event: string;
66 constructor(error: TimedOutTimeoutError, timings: Timings, request: Request);
67}
68/**
69An error to be thrown when reading from response stream fails.
70*/
71export declare class ReadError extends RequestError {
72 readonly request: Request;
73 readonly response: Response;
74 readonly timings: Timings;
75 constructor(error: Error, request: Request);
76}
77/**
78An error which always triggers a new retry when thrown.
79*/
80export declare class RetryError extends RequestError {
81 constructor(request: Request);
82}
83/**
84An error to be thrown when the request is aborted by AbortController.
85*/
86export declare class AbortError extends RequestError {
87 constructor(request: Request);
88}
89export {};