(
pathOrUrl: string,
method: HTTPMethod,
headers: StringMap<string> | undefined,
body: ArrayBuffer | Uint8Array | undefined,
)
| 25 | constructor(readonly baseUrl?: string | undefined) {} |
| 26 | |
| 27 | perform( |
| 28 | pathOrUrl: string, |
| 29 | method: HTTPMethod, |
| 30 | headers: StringMap<string> | undefined, |
| 31 | body: ArrayBuffer | Uint8Array | undefined, |
| 32 | ): CancelablePromise<HTTPResponse> { |
| 33 | let cancelFn: (() => void) | undefined; |
| 34 | let rejectFn: ((reason: unknown) => void) | undefined; |
| 35 | const promise = new Promise<HTTPResponse>((resolve, reject) => { |
| 36 | rejectFn = reject; |
| 37 | try { |
| 38 | const request: HTTPRequest = { |
| 39 | url: makeURL(this.baseUrl, pathOrUrl), |
| 40 | method, |
| 41 | headers, |
| 42 | body, |
| 43 | }; |
| 44 | |
| 45 | cancelFn = performRequest(request, (response, error) => { |
| 46 | if (response) { |
| 47 | resolve(response); |
| 48 | } else { |
| 49 | // A request manager reports its failure as text, so wrap it: callers should not have to |
| 50 | // ask whether the rejection they caught is a string or an Error. |
| 51 | reject(error instanceof Error ? error : new Error(String(error))); |
| 52 | } |
| 53 | }); |
| 54 | } catch (err: unknown) { |
| 55 | reject(err); |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | // No request manager reports a cancelled request, so without this the promise never settles. |
no test coverage detected