MCPcopy Create free account
hub / github.com/Snapchat/Valdi / perform

Method perform

src/valdi_modules/src/valdi/valdi_http/src/HTTPClient.ts:27–56  ·  view source on GitHub ↗
(
    pathOrUrl: string,
    method: HTTPMethod,
    headers: StringMap<string> | undefined,
    body: ArrayBuffer | Uint8Array | undefined,
  )

Source from the content-addressed store, hash-verified

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.

Callers 5

getMethod · 0.95
putMethod · 0.95
postMethod · 0.95
deleteMethod · 0.95
headMethod · 0.95

Calls 5

makeURLFunction · 0.85
performRequestFunction · 0.85
rejectFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected