From befb13c4b5eb362574a1c72d96b5a10d786d9e45 Mon Sep 17 00:00:00 2001 From: Marc Farra Date: Tue, 12 Sep 2023 13:09:20 +0200 Subject: [PATCH] get errors from server --- .../documents/single-edit/use-document-create.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/scripts/components/documents/single-edit/use-document-create.js b/app/assets/scripts/components/documents/single-edit/use-document-create.js index e0ac6a41..75378407 100644 --- a/app/assets/scripts/components/documents/single-edit/use-document-create.js +++ b/app/assets/scripts/components/documents/single-edit/use-document-create.js @@ -18,7 +18,20 @@ export function useDocumentCreate(title, alias, isPdfType) { const result = await createAtbd(title, alias, isPdfType); if (result.error) { - processToast.error(`An error occurred: ${result.error.message}`); + if (result.error.response) { + const { status } = result.error.response; + if (status === 400) { + processToast.error( + `An error occurred: ${result.error.response.data.detail}` + ); + } else { + processToast.error( + `An error occurred: ${result.error.response.statusText}` + ); + } + } else { + processToast.error(`An error occurred: ${result.error.message}`); + } } else { processToast.success('Document successfully created'); // To trigger the modals to open from other pages, we use the history