UNPKG

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