1 | /// <reference types="node" resolution-mode="require"/>
|
2 | import type { Buffer } from 'node:buffer';
|
3 | import type PCancelable from 'p-cancelable';
|
4 | import { RequestError } from '../core/errors.js';
|
5 | import type Request from '../core/index.js';
|
6 | import { type RequestEvents } from '../core/index.js';
|
7 | import type { Response } from '../core/response.js';
|
8 | /**
|
9 | An error to be thrown when the request is aborted with `.cancel()`.
|
10 | */
|
11 | export declare class CancelError extends RequestError {
|
12 | readonly response: Response;
|
13 | constructor(request: Request);
|
14 | /**
|
15 | Whether the promise is canceled.
|
16 | */
|
17 | get isCanceled(): boolean;
|
18 | }
|
19 | export interface CancelableRequest<T extends Response | Response['body'] = Response['body']> extends PCancelable<T>, RequestEvents<CancelableRequest<T>> {
|
20 | /**
|
21 | A shortcut method that gives a Promise returning a JSON object.
|
22 |
|
23 | It is semantically the same as settings `options.resolveBodyOnly` to `true` and `options.responseType` to `'json'`.
|
24 | */
|
25 | json: <ReturnType>() => CancelableRequest<ReturnType>;
|
26 | /**
|
27 | A shortcut method that gives a Promise returning a [Buffer](https://nodejs.org/api/buffer.html).
|
28 |
|
29 | It is semantically the same as settings `options.resolveBodyOnly` to `true` and `options.responseType` to `'buffer'`.
|
30 | */
|
31 | buffer: () => CancelableRequest<Buffer>;
|
32 | /**
|
33 | A shortcut method that gives a Promise returning a string.
|
34 |
|
35 | It is semantically the same as settings `options.resolveBodyOnly` to `true` and `options.responseType` to `'text'`.
|
36 | */
|
37 | text: () => CancelableRequest<string>;
|
38 | }
|