MCPcopy
hub / github.com/continuedev/continue / makeAuthenticatedRequest

Function makeAuthenticatedRequest

extensions/cli/src/util/apiClient.ts:60–122  ·  view source on GitHub ↗
(
  endpoint: string,
  options: ApiRequestOptions = {},
)

Source from the content-addressed store, hash-verified

58 * Hub authentication has been removed - requests are made without auth headers.
59 */
60export async function makeAuthenticatedRequest<T = any>(
61 endpoint: string,
62 options: ApiRequestOptions = {},
63): Promise<ApiResponse<T>> {
64 const { method = "GET", body, headers = {} } = options;
65
66 const requestOptions: RequestInit = {
67 method,
68 headers: {
69 "Content-Type": "application/json",
70 ...headers,
71 },
72 };
73
74 if (body) {
75 requestOptions.body =
76 typeof body === "string" ? body : JSON.stringify(body);
77 }
78
79 try {
80 const url = new URL(endpoint, env.apiBase);
81 logger.debug(`Making ${method} request to: ${url.toString()}`);
82
83 const response = await fetch(url, requestOptions);
84
85 if (!response.ok) {
86 const errorText = await response.text();
87 logger.error(`API request failed: ${response.status} ${errorText}`);
88 throw new ApiRequestError(
89 response.status,
90 response.statusText,
91 errorText,
92 );
93 }
94
95 let data: T;
96 const contentType = response.headers.get("content-type");
97 if (contentType && contentType.includes("application/json")) {
98 data = await response.json();
99 } else {
100 data = (await response.text()) as T;
101 }
102
103 logger.debug(`API request successful: ${response.status}`);
104
105 return {
106 data,
107 status: response.status,
108 ok: response.ok,
109 };
110 } catch (error) {
111 if (
112 error instanceof AuthenticationRequiredError ||
113 error instanceof ApiRequestError
114 ) {
115 throw error;
116 }
117

Callers 5

getFunction · 0.85
postFunction · 0.85
putFunction · 0.85
delFunction · 0.85
apiClient.test.tsFile · 0.85

Calls 5

textMethod · 0.80
errorMethod · 0.80
getMethod · 0.65
fetchFunction · 0.50
debugMethod · 0.45

Tested by

no test coverage detected