From f18fa3f4d80ef81b12b018cd26177cc3e8548d40 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Thu, 3 Sep 2020 00:25:21 +0200 Subject: [PATCH] handle 400 like 500 as errors --- components/wizard/context/wizardStore.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/wizard/context/wizardStore.tsx b/components/wizard/context/wizardStore.tsx index e32d84f..9f9db25 100644 --- a/components/wizard/context/wizardStore.tsx +++ b/components/wizard/context/wizardStore.tsx @@ -160,6 +160,18 @@ async function createBooking(formData: WizardFormData) { referrerPolicy: 'no-referrer', body: JSON.stringify(formData), }) + + if (response.status === 400) { + const error = await response.json() + throw Error(error.message) + } + + if (!response.ok) { + throw Error( + 'Sorry, konnte nicht gespeichert werden. Bitte versuch es später nochmal!' + ) + } + return response.json() }