| 193 | }; |
| 194 | |
| 195 | export const sendRequest = async ( |
| 196 | config: OpenAPIConfig, |
| 197 | options: ApiRequestOptions, |
| 198 | url: string, |
| 199 | body: any, |
| 200 | formData: FormData | undefined, |
| 201 | headers: Headers, |
| 202 | onCancel: OnCancel |
| 203 | ): Promise<Response> => { |
| 204 | const controller = new AbortController(); |
| 205 | |
| 206 | const request: RequestInit = { |
| 207 | headers, |
| 208 | body: body ?? formData, |
| 209 | method: options.method, |
| 210 | signal: controller.signal, |
| 211 | }; |
| 212 | |
| 213 | if (config.WITH_CREDENTIALS) { |
| 214 | request.credentials = config.CREDENTIALS; |
| 215 | } |
| 216 | |
| 217 | onCancel(() => controller.abort()); |
| 218 | |
| 219 | return await fetch(url, request); |
| 220 | }; |
| 221 | |
| 222 | export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => { |
| 223 | if (responseHeader) { |