From b75816b3c6ac846934cdba244fbc3a014ad154c4 Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Wed, 15 Dec 2021 11:18:35 +0100 Subject: [PATCH] Fixing problem with missing error message --- .../sponsor/register/stepRegistration.tsx | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/frontend/src/routes/sponsor/register/stepRegistration.tsx b/frontend/src/routes/sponsor/register/stepRegistration.tsx index ff53f1db..7e965b8e 100644 --- a/frontend/src/routes/sponsor/register/stepRegistration.tsx +++ b/frontend/src/routes/sponsor/register/stepRegistration.tsx @@ -96,15 +96,29 @@ export default function StepRegistration() { fetch('/api/ui/v1/invite/', submitJsonOpts('POST', payload)) .then((res) => { if (!res.ok) { - res.text().then((text) => { - setSubmitState(SubmitState.SubmitFailure) - setSubmitErrorReport({ - errorHeading: t('error.invitationCreationFailedHeader'), - statusCode: res.status, - statusText: res.statusText, - errorBodyText: text, + // Try to extract data from body of error message + res + .text() + .then((text) => { + setSubmitState(SubmitState.SubmitFailure) + setSubmitErrorReport({ + errorHeading: t('error.invitationCreationFailedHeader'), + statusCode: res.status, + statusText: res.statusText, + errorBodyText: text, + }) + }) + .catch((error) => { + // Extracting data from body failed, just show an error message with no body text + console.error('error', error) + setSubmitErrorReport({ + errorHeading: t('error.invitationCreationFailedHeader'), + statusCode: res.status, + statusText: res.statusText, + errorBodyText: undefined, + }) + setSubmitState(SubmitState.SubmitFailure) }) - }) } else { return res.text() } @@ -118,7 +132,7 @@ export default function StepRegistration() { } }) .catch((error) => { - console.log('error', error) + console.error('error', error) setSubmitState(SubmitState.SubmitFailure) }) } -- GitLab