Include more details when throwing errors for debugging in Sentry * WIP throw errors with more details for debugging in Sentry * Fix throwing response-data * Clearer message when a response fails * Add message to errors * better typings * . * Try to send profileID and membershipNumber to Sentry when we fail to parse the apiResponse * rename notFound -> notFoundError * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/add-error-details-for-sentry Approved-by: Linus Flood
22 lines
575 B
TypeScript
22 lines
575 B
TypeScript
export async function getResponseBody(
|
|
response: Response
|
|
): Promise<string | Record<string, unknown>> {
|
|
const clone = response.clone()
|
|
|
|
const contentType = clone.headers.get("content-type")
|
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
try {
|
|
return await clone.json()
|
|
} catch {
|
|
try {
|
|
return await clone.text()
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
return `Unable to extract body '${message}'`
|
|
}
|
|
}
|
|
}
|
|
|
|
return await clone.text()
|
|
}
|