( config: OpenAPIConfig, options: ApiRequestOptions<T>, axiosClient: AxiosInstance = axios, )
| 320 | * @throws ApiError |
| 321 | */ |
| 322 | export 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 | } |
nothing calls this directly
no test coverage detected