UNPKG

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