MCPcopy
hub / github.com/di-sukharev/opencommit / makeRequest

Method makeRequest

out/cli.cjs:69725–69767  ·  view source on GitHub ↗
(optionsInput, retriesRemaining)

Source from the content-addressed store, hash-verified

69723 return !headers ? {} : Symbol.iterator in headers ? Object.fromEntries(Array.from(headers).map((header) => [...header])) : { ...headers };
69724 }
69725 makeStatusError(status, error, message, headers) {
69726 return APIError.generate(status, error, message, headers);
69727 }
69728 request(options, remainingRetries = null) {
69729 return new APIPromise(this.makeRequest(options, remainingRetries));
69730 }
69731 async makeRequest(optionsInput, retriesRemaining) {
69732 const options = await optionsInput;
69733 if (retriesRemaining == null) {
69734 retriesRemaining = options.maxRetries ?? this.maxRetries;
69735 }
69736 await this.prepareOptions(options);
69737 const { req, url: url2, timeout } = this.buildRequest(options);
69738 await this.prepareRequest(req, { url: url2, options });
69739 debug("request", url2, options, req.headers);
69740 if (options.signal?.aborted) {
69741 throw new APIUserAbortError();
69742 }
69743 const controller = new AbortController();
69744 const response = await this.fetchWithTimeout(url2, req, timeout, controller).catch(castToError);
69745 if (response instanceof Error) {
69746 if (options.signal?.aborted) {
69747 throw new APIUserAbortError();
69748 }
69749 if (retriesRemaining) {
69750 return this.retryRequest(options, retriesRemaining);
69751 }
69752 if (response.name === "AbortError") {
69753 throw new APIConnectionTimeoutError();
69754 }
69755 throw new APIConnectionError({ cause: response });
69756 }
69757 const responseHeaders = createResponseHeaders(response.headers);
69758 if (!response.ok) {
69759 if (retriesRemaining && this.shouldRetry(response)) {
69760 const retryMessage2 = `retrying, ${retriesRemaining} attempts remaining`;
69761 debug(`response (error; ${retryMessage2})`, response.status, url2, responseHeaders);
69762 return this.retryRequest(options, retriesRemaining, responseHeaders);
69763 }
69764 const errText = await response.text().catch((e3) => castToError(e3).message);
69765 const errJSON = safeJSON(errText);
69766 const errMessage = errJSON ? void 0 : errText;
69767 const retryMessage = retriesRemaining ? `(error; no more retries left)` : `(error; not retryable)`;
69768 debug(`response (error; ${retryMessage})`, response.status, url2, responseHeaders, errMessage);
69769 const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
69770 throw err;

Callers 4

requestMethod · 0.80
requestAPIListMethod · 0.80
retryRequestMethod · 0.80
sendRequestMethod · 0.80

Calls 15

debugFunction · 0.85
createResponseHeadersFunction · 0.85
castToErrorFunction · 0.85
safeJSONFunction · 0.85
rejectFunction · 0.85
isReadableStream2Function · 0.85
isArrayBuffer2Function · 0.85
debug4Function · 0.85
createResponseHeaders2Function · 0.85
castToError2Function · 0.85
safeJSON2Function · 0.85
prepareOptionsMethod · 0.80

Tested by

no test coverage detected