| 208 | }; |
| 209 | |
| 210 | export const getResponseBody = async (response: Response): Promise<unknown> => { |
| 211 | if (response.status !== 204) { |
| 212 | try { |
| 213 | const contentType = response.headers.get('Content-Type'); |
| 214 | if (contentType) { |
| 215 | const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/']; |
| 216 | if (contentType.includes('application/json') || contentType.includes('+json')) { |
| 217 | return await response.json(); |
| 218 | } else if (binaryTypes.some(type => contentType.includes(type))) { |
| 219 | return await response.blob(); |
| 220 | } else if (contentType.includes('multipart/form-data')) { |
| 221 | return await response.formData(); |
| 222 | } else if (contentType.includes('text/')) { |
| 223 | return await response.text(); |
| 224 | } |
| 225 | } |
| 226 | } catch (error) { |
| 227 | console.error(error); |
| 228 | } |
| 229 | } |
| 230 | return undefined; |
| 231 | }; |
| 232 | |
| 233 | export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { |
| 234 | const errors: Record<number, string> = { |