MCPcopy
hub / github.com/agent-infra/sandbox / fetcherImpl

Function fetcherImpl

sdk/js/src/core/fetcher/Fetcher.ts:221–362  ·  view source on GitHub ↗
(args: Fetcher.Args)

Source from the content-addressed store, hash-verified

219}
220
221export async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse<R, Fetcher.Error>> {
222 const url = createRequestUrl(args.url, args.queryParameters);
223 const requestBody: BodyInit | undefined = await getRequestBody({
224 body: args.body,
225 type: args.requestType ?? "other",
226 });
227 const fetchFn = args.fetchFn ?? (await getFetchFn());
228 const headers = await getHeaders(args);
229 const logger = createLogger(args.logging);
230
231 if (logger.isDebug()) {
232 const metadata = {
233 method: args.method,
234 url: redactUrl(url),
235 headers: redactHeaders(headers),
236 queryParameters: redactQueryParameters(args.queryParameters),
237 hasBody: requestBody != null,
238 };
239 logger.debug("Making HTTP request", metadata);
240 }
241
242 try {
243 const response = await requestWithRetries(
244 async () =>
245 makeRequest(
246 fetchFn,
247 url,
248 args.method,
249 headers,
250 requestBody,
251 args.timeoutMs,
252 args.abortSignal,
253 args.withCredentials,
254 args.duplex,
255 ),
256 args.maxRetries,
257 );
258
259 if (response.status >= 200 && response.status < 400) {
260 if (logger.isDebug()) {
261 const metadata = {
262 method: args.method,
263 url: redactUrl(url),
264 statusCode: response.status,
265 };
266 logger.debug("HTTP request succeeded", metadata);
267 }
268 return {
269 ok: true,
270 body: (await getResponseBody(response, args.responseType)) as R,
271 headers: response.headers,
272 rawResponse: toRawResponse(response),
273 };
274 } else {
275 if (logger.isError()) {
276 const metadata = {
277 method: args.method,
278 url: redactUrl(url),

Callers 1

fetcher.test.tsFile · 0.90

Calls 15

createRequestUrlFunction · 0.90
getRequestBodyFunction · 0.90
getFetchFnFunction · 0.90
createLoggerFunction · 0.90
requestWithRetriesFunction · 0.90
makeRequestFunction · 0.90
getResponseBodyFunction · 0.90
toRawResponseFunction · 0.90
getErrorResponseBodyFunction · 0.90
toJsonFunction · 0.90
getHeadersFunction · 0.85
redactUrlFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…