interface CancelableRequest<T> {
    json: (<ReturnType>() => CancelableRequest<ReturnType>);
    buffer: (() => CancelableRequest<Buffer>);
    text: (() => CancelableRequest<string>);
    on: GotEventFunction<CancelableRequest<T>>;
    once: GotEventFunction<CancelableRequest<T>>;
    off: GotEventFunction<CancelableRequest<T>>;
    isCanceled: boolean;
    cancel: ((reason?: string) => void);
    [toStringTag]: string;
    finally(onfinally?: null | (() => void)): Promise<T>;
    then<TResult1, TResult2>(onfulfilled?: null | ((value: T) => TResult1 | PromiseLike<TResult1>), onrejected?: null | ((reason: any) => TResult2 | PromiseLike<TResult2>)): Promise<TResult1 | TResult2>;
    catch<TResult>(onrejected?: null | ((reason: any) => TResult | PromiseLike<TResult>)): Promise<T | TResult>;
}

Type Parameters

Hierarchy (view full)

Properties

A shortcut method that gives a Promise returning a JSON object.

It is semantically the same as settings options.resolveBodyOnly to true and options.responseType to 'json'.

buffer: (() => CancelableRequest<Buffer>)

A shortcut method that gives a Promise returning a Buffer.

It is semantically the same as settings options.resolveBodyOnly to true and options.responseType to 'buffer'.

text: (() => CancelableRequest<string>)

A shortcut method that gives a Promise returning a string.

It is semantically the same as settings options.resolveBodyOnly to true and options.responseType to 'text'.

isCanceled: boolean

Whether the promise is canceled.

cancel: ((reason?: string) => void)

Cancel the promise and optionally provide a reason.

The cancellation is synchronous. Calling it after the promise has settled or multiple times does nothing.

Type declaration

    • (reason?): void
    • Parameters

      • Optionalreason: string

        The cancellation reason to reject the promise with.

      Returns void

[toStringTag]: string

Methods

  • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

    Parameters

    • Optionalonfinally: null | (() => void)

      The callback to execute when the Promise is settled (fulfilled or rejected).

    Returns Promise<T>

    A Promise for the completion of the callback.

  • Attaches callbacks for the resolution and/or rejection of the Promise.

    Type Parameters

    • TResult1 = T
    • TResult2 = never

    Parameters

    Returns Promise<TResult1 | TResult2>

    A Promise for the completion of which ever callback is executed.

  • Attaches a callback for only the rejection of the Promise.

    Type Parameters

    • TResult = never

    Parameters

    • Optionalonrejected: null | ((reason: any) => TResult | PromiseLike<TResult>)

      The callback to execute when the Promise is rejected.

    Returns Promise<T | TResult>

    A Promise for the completion of the callback.