UNPKG

got

Version:

Human-friendly and powerful HTTP request library for Node.js

135 lines (130 loc) • 4.44 kB
import type { StandardSchemaV1Issue } from './standard-schema.js'; import type { Timings } from './utils/timer.js'; import type Options from './options.js'; import type { TimeoutError as TimedOutTimeoutError } from './timed-out.js'; import type { PlainResponse, Response } from './response.js'; import type Request from './index.js'; type Error = NodeJS.ErrnoException; export declare const normalizeError: (error: unknown) => Error; /** An error to be thrown when a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`. */ export declare class RequestError<T = unknown> extends Error { name: string; code: string; input?: string; stack: string; readonly options: Options; readonly response?: Response<T>; readonly request?: Request; readonly timings?: Timings; constructor(message: string, error: Partial<Error & { code?: string; }>, self: Request | Options, response?: PlainResponse); } /** An error to be thrown when the server redirects you more than ten times. Includes a `response` property. */ export declare class MaxRedirectsError extends RequestError { name: string; code: string; readonly response: Response; readonly request: Request; constructor(request: Request); } /** An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304. Includes a `response` property. */ export declare class HTTPError<T = unknown> extends RequestError<T> { name: string; code: string; readonly response: Response<T>; readonly request: Request; constructor(response: PlainResponse); } /** An error to be thrown when a cache method fails. For example, if the database goes down or there's a filesystem error. */ export declare class CacheError extends RequestError { name: string; code: string; readonly request: Request; constructor(error: Error, request: Request); } /** An error to be thrown when the request body is a stream and an error occurs while reading from that stream. */ export declare class UploadError extends RequestError { name: string; code: string; readonly request: Request; constructor(error: Error, request: Request); } /** An error to be thrown when the request is aborted due to a timeout. Includes an `event` and `timings` property. */ export declare class TimeoutError extends RequestError { name: string; code: string; readonly request: Request; readonly timings: Timings; readonly event: string; constructor(error: TimedOutTimeoutError, timings: Timings, request: Request); } /** An error to be thrown when reading from response stream fails. */ export declare class ReadError extends RequestError { name: string; code: string; readonly request: Request; readonly response: Response; constructor(error: Error, request: Request); } /** An error which always triggers a new retry when thrown. */ export declare class RetryError extends RequestError { name: string; code: string; constructor(request: Request); } /** An error to be thrown when the request is aborted by AbortController. */ export declare class AbortError extends RequestError { name: string; code: string; constructor(request: Request); } /** An error to be thrown when the response body does not match the [Standard Schema](https://standardschema.dev) validator passed to `.json(schema)`. Includes an `issues` property with the issues from the schema. Each issue has a `message` and an optional `path`. It intentionally does not extend `RequestError`, because the request succeeded. The user-provided schema did not accept the data, so it has no `code`, `options`, `request`, `response` or `timings` property, and it is not passed to `beforeError` hooks. @example ``` import got, {SchemaValidationError} from 'got'; import {z} from 'zod'; const userSchema = z.object({name: z.string()}); try { const user = await got('https://example.com/user').json(userSchema); console.log(user.name); } catch (error) { if (error instanceof SchemaValidationError) { console.error(error.issues); } else { throw error; } } ``` */ export declare class SchemaValidationError extends Error { name: string; readonly issues: readonly StandardSchemaV1Issue[]; constructor(issues: readonly StandardSchemaV1Issue[]); } export {};