MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / post

Method post

packages/sdks/sdk/src/api.ts:43–75  ·  view source on GitHub ↗
(
    url: string,
    data: ReqBody,
    options: FetchOptions,
    attempt: number,
  )

Source from the content-addressed store, hash-verified

41 }
42
43 private async post<ReqBody, ResBody>(
44 url: string,
45 data: ReqBody,
46 options: FetchOptions,
47 attempt: number,
48 ): Promise<ResBody | null> {
49 try {
50 const response = await fetch(url, {
51 method: 'POST',
52 headers: await this.resolveHeaders(),
53 body: data ? JSON.stringify(data ?? {}) : undefined,
54 keepalive: true,
55 ...options,
56 });
57
58 if (response.status === 401) return null;
59
60 if (response.status !== 200 && response.status !== 202) {
61 throw new Error(`HTTP error! status: ${response.status}`);
62 }
63
64 const responseText = await response.text();
65 return responseText ? JSON.parse(responseText) : null;
66 } catch (error) {
67 if (attempt < this.maxRetries) {
68 const delay = this.initialRetryDelay * 2 ** attempt;
69 await new Promise((resolve) => setTimeout(resolve, delay));
70 return this.post<ReqBody, ResBody>(url, data, options, attempt + 1);
71 }
72 console.error('Max retries reached:', error);
73 return null;
74 }
75 }
76
77 async fetch<ReqBody, ResBody>(
78 path: string,

Callers 1

fetchMethod · 0.95

Calls 5

resolveHeadersMethod · 0.95
parseMethod · 0.80
fetchFunction · 0.50
stringifyMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected