From b3cac753d67993d3657eaa5c38583e48ea01b761 Mon Sep 17 00:00:00 2001 From: Tobias Odendahl Date: Wed, 7 May 2025 02:27:05 +0200 Subject: [PATCH] feat(ui): display the actual error message on unpublish if available (#11898) ### What? If an error occurs while unpublishing a document in the edit view UI, the toast which shows the error message now displays the actual message which is sent from the server, if available. ### Why? Only a generic error message was shown if an unpublish operation failed. Some errors might be solvable by the user, so that there is value in showing the actual, actionable error message instead of a generic one. ### How? The server response is parsed for error message if an unpublish operation fails and displayed in the toast, instead of the generic error message. ![image](https://github.com/user-attachments/assets/774d68c6-b36b-4447-93a0-b437845694a9) --- packages/ui/src/elements/Status/index.tsx | 15 ++++++++- test/versions/collections/ErrorOnUnpublish.ts | 33 +++++++++++++++++++ test/versions/config.ts | 2 ++ test/versions/e2e.spec.ts | 19 +++++++++++ test/versions/payload-types.ts | 27 +++++++++++++++ test/versions/slugs.ts | 1 + 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 test/versions/collections/ErrorOnUnpublish.ts diff --git a/packages/ui/src/elements/Status/index.tsx b/packages/ui/src/elements/Status/index.tsx index 0ae421196..6e473e8fc 100644 --- a/packages/ui/src/elements/Status/index.tsx +++ b/packages/ui/src/elements/Status/index.tsx @@ -117,7 +117,19 @@ export const Status: React.FC = () => { setUnpublishedVersionCount(0) } } else { - toast.error(t('error:unPublishingDocument')) + try { + const json = await res.json() + if (json.errors?.[0]?.message) { + toast.error(json.errors[0].message) + } else if (json.error) { + toast.error(json.error) + } else { + toast.error(t('error:unPublishingDocument')) + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (err) { + toast.error(t('error:unPublishingDocument')) + } } }, [ @@ -154,6 +166,7 @@ export const Status: React.FC = () => {