文档导航

类:APIPromise<T>

类:APIPromise<T>

解析结果的 promise,同时可以访问 HTTP 响应。

非 2xx 响应会以 APIError 拒绝,经由 asResponse() 时也一样。

继承

  • Promise<T>

类型参数

T

T

构造函数

构造函数

new APIPromise<T>(responsePromise, parseResponse): APIPromise<T>;

参数

responsePromise

Promise<Response>

parseResponse

(response) => Promise<T>

返回值

APIPromise<T>

覆盖

Promise<T>.constructor

方法

asResponse()

asResponse(): Promise<Response>;

解析为原始的 Response,不解析 body。SDK 请求会在请求超时内先把完整 body 缓冲好再移交;之后读取它由调用方负责。body 归调用方所有; 不要对同一个 promise 再 await 解析后的结果。

返回值

Promise<Response>


catch()

catch<TResult>(onrejected?): Promise<T | TResult>;

为 Promise 仅附加一个拒绝时的回调。

类型参数

TResult

TResult = never

参数

onrejected?

((reason) => TResult | PromiseLike<TResult>) | null

Promise 被拒绝时执行的回调。

返回值

Promise<T | TResult>

回调完成的 Promise。

覆盖

Promise.catch

finally()

finally(onfinally?): Promise<T>;

附加一个回调,在 Promise 敲定(已完成或已拒绝)时调用。已解析的值 无法从回调里修改。

参数

onfinally?

(() => void) | null

Promise 敲定(已完成或已拒绝)时执行的回调。

返回值

Promise<T>

回调完成的 Promise。

覆盖

Promise.finally

map()

map<U>(fn): APIPromise<U>;

变换解析后的结果,共享同一个 HTTP 响应与同一次 body 解析。

类型参数

U

U

参数

fn

(data) => U

返回值

APIPromise<U>


then()

then<TResult1, TResult2>(onfulfilled?, onrejected?): Promise<TResult1 | TResult2>;

为 Promise 的解析和/或拒绝附加回调。

类型参数

TResult1

TResult1 = T

TResult2

TResult2 = never

参数

onfulfilled?

((value) => TResult1 | PromiseLike<TResult1>) | null

Promise 被解析时执行的回调。

onrejected?

((reason) => TResult2 | PromiseLike<TResult2>) | null

Promise 被拒绝时执行的回调。

返回值

Promise<TResult1 | TResult2>

所执行的那个回调完成的 Promise。

覆盖

Promise.then

withResponse()

withResponse(): Promise<WithResponse<T>>;

返回解析后的结果、HTTP 响应和请求 ID。

返回值

Promise<WithResponse<T>>