文件導航

類: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>>