| 230 | }; |
| 231 | |
| 232 | export const getResponseBody = async (response: Response): Promise<any> => { |
| 233 | if (response.status !== 204) { |
| 234 | try { |
| 235 | const contentType = response.headers.get('Content-Type'); |
| 236 | if (contentType) { |
| 237 | const jsonTypes = ['application/json', 'application/problem+json'] |
| 238 | const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type)); |
| 239 | if (isJSON) { |
| 240 | return await response.json(); |
| 241 | } else { |
| 242 | return await response.text(); |
| 243 | } |
| 244 | } |
| 245 | } catch (error) { |
| 246 | console.error(error); |
| 247 | } |
| 248 | } |
| 249 | return undefined; |
| 250 | }; |
| 251 | |
| 252 | export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => { |
| 253 | const errors: Record<number, string> = { |