From cf6070e71d77c0c51c2a3e1e1906f5ad8568777a Mon Sep 17 00:00:00 2001 From: Andcool-Systems Date: Fri, 20 Sep 2024 17:44:21 +0300 Subject: [PATCH] fixed error displaying on create --- src/app/workshop/[id]/client_code.tsx | 6 +++++- src/app/workshop/create/page.tsx | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app/workshop/[id]/client_code.tsx b/src/app/workshop/[id]/client_code.tsx index 3406815..0c5de90 100644 --- a/src/app/workshop/[id]/client_code.tsx +++ b/src/app/workshop/[id]/client_code.tsx @@ -520,7 +520,11 @@ const EditElement = ({ bandage, onClose }: { bandage: Interfaces.Bandage, onClos return; } if (response.status === 400) { - alert(response.data.message.map((str: string) => capitalize(str)).join(', ')); + if (typeof response.data.message === 'object') { + alert(response.data.message.map((str: string) => capitalize(str)).join('\n') || `Unhandled error: ${response.status}`); + } else { + alert(response.data.message_ru || response.data.message); + } } }) } diff --git a/src/app/workshop/create/page.tsx b/src/app/workshop/create/page.tsx index b852d53..cf42014 100644 --- a/src/app/workshop/create/page.tsx +++ b/src/app/workshop/create/page.tsx @@ -232,7 +232,11 @@ const Editor = ({ onBandageChange, onColorChange, onColorableChange, onBandageCh if (response.status !== 201) { const error_el = document.getElementById('create_error') as HTMLLabelElement; if (error_el) { - error_el.innerText = response.data.message.map((str: string) => capitalize(str)).join('\n') || `Unhandled error: ${response.status}`; + if (typeof response.data.message === 'object') { + error_el.innerText = response.data.message.map((str: string) => capitalize(str)).join('\n') || `Unhandled error: ${response.status}`; + } else { + error_el.innerText = response.data.message_ru || response.data.message; + } } } else { router.replace(`/workshop/${response.data.external_id}`); @@ -259,7 +263,7 @@ const Editor = ({ onBandageChange, onColorChange, onColorableChange, onBandageCh heightVal={height} /> } -

+