MCPcopy Create free account
hub / github.com/0010aor/FlashNotes / request

Function request

frontend/src/client/core/request.ts:322–374  ·  view source on GitHub ↗
(
  config: OpenAPIConfig,
  options: ApiRequestOptions<T>,
  axiosClient: AxiosInstance = axios,
)

Source from the content-addressed store, hash-verified

320 * @throws ApiError
321 */
322export const request = <T>(
323 config: OpenAPIConfig,
324 options: ApiRequestOptions<T>,
325 axiosClient: AxiosInstance = axios,
326): CancelablePromise<T> => {
327 return new CancelablePromise(async (resolve, reject, onCancel) => {
328 try {
329 const url = getUrl(config, options)
330 const formData = getFormData(options)
331 const body = getRequestBody(options)
332 const headers = await getHeaders(config, options)
333
334 if (!onCancel.isCancelled) {
335 let response = await sendRequest<T>(
336 config,
337 options,
338 url,
339 body,
340 formData,
341 headers,
342 onCancel,
343 axiosClient,
344 )
345
346 for (const fn of config.interceptors.response._fns) {
347 response = await fn(response)
348 }
349
350 const responseBody = getResponseBody(response)
351 const responseHeader = getResponseHeader(response, options.responseHeader)
352
353 let transformedBody = responseBody
354 if (options.responseTransformer && isSuccess(response.status)) {
355 transformedBody = await options.responseTransformer(responseBody)
356 }
357
358 const result: ApiResult = {
359 url,
360 ok: isSuccess(response.status),
361 status: response.status,
362 statusText: response.statusText,
363 body: responseHeader ?? transformedBody,
364 }
365
366 catchErrorCodes(options, result)
367
368 resolve(result.body)
369 }
370 } catch (error) {
371 reject(error)
372 }
373 })
374}

Callers

nothing calls this directly

Calls 9

getUrlFunction · 0.85
getFormDataFunction · 0.85
getRequestBodyFunction · 0.85
getHeadersFunction · 0.85
getResponseBodyFunction · 0.85
getResponseHeaderFunction · 0.85
isSuccessFunction · 0.85
catchErrorCodesFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected