MCPcopy
hub / github.com/ing-bank/lion / fetch

Method fetch

packages/ajax/src/Ajax.js:146–180  ·  view source on GitHub ↗

* Fetch by calling the registered request and response interceptors. * * @param {RequestInfo} info * @param {RequestInit & Partial } [init] * @param {Boolean} [parseErrorResponse] * @returns {Promise }

(info, init, parseErrorResponse = false)

Source from the content-addressed store, hash-verified

144 * @returns {Promise<Response>}
145 */
146 async fetch(info, init, parseErrorResponse = false) {
147 const request = /** @type {CacheRequest} */ (new Request(info, { ...init }));
148 request.cacheOptions = init?.cacheOptions;
149 request.params = init?.params;
150
151 // run request interceptors, returning directly and skipping the network
152 const interceptedRequestOrResponse = await this.__interceptRequest(request);
153 if (interceptedRequestOrResponse instanceof Response) {
154 const response = /** @type {CacheResponse} */ (interceptedRequestOrResponse);
155 response.request = request;
156 if (isFailedResponse(interceptedRequestOrResponse)) {
157 throw new AjaxFetchError(
158 request,
159 response,
160 parseErrorResponse ? await this.__attemptParseFailedResponseBody(response) : undefined,
161 );
162 }
163 // prevent network request, return cached response
164 return response;
165 }
166
167 const response = /** @type {CacheResponse} */ (await fetch(interceptedRequestOrResponse));
168 response.request = interceptedRequestOrResponse;
169
170 const interceptedResponse = await this.__interceptResponse(response);
171
172 if (isFailedResponse(interceptedResponse)) {
173 throw new AjaxFetchError(
174 request,
175 response,
176 parseErrorResponse ? await this.__attemptParseFailedResponseBody(response) : undefined,
177 );
178 }
179 return interceptedResponse;
180 }
181
182 /**
183 * Fetch by calling the registered request and response

Callers 3

fetchJsonMethod · 0.95
Ajax.test.jsFile · 0.80

Calls 4

__interceptRequestMethod · 0.95
__interceptResponseMethod · 0.95
isFailedResponseFunction · 0.85

Tested by

no test coverage detected