From 707cb8881582473922d1c40106bf508a5a6c5c9d Mon Sep 17 00:00:00 2001 From: JORGE Date: Mon, 9 Dec 2024 10:30:36 -0400 Subject: [PATCH] [TM-1552] fix display of error messages --- .../ResourceTabs/PolygonReviewTab/index.tsx | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/admin/components/ResourceTabs/PolygonReviewTab/index.tsx b/src/admin/components/ResourceTabs/PolygonReviewTab/index.tsx index bb525ce2..92126419 100644 --- a/src/admin/components/ResourceTabs/PolygonReviewTab/index.tsx +++ b/src/admin/components/ResourceTabs/PolygonReviewTab/index.tsx @@ -347,23 +347,31 @@ const PolygonReviewTab: FC = props => { setSubmitPolygonLoaded(false); hideLoader(); } catch (error) { - if (error && typeof error === "object" && "message" in error) { - let errorMessage = error.message; - if (typeof errorMessage === "string") { - const parsedMessage = JSON.parse(errorMessage); - if (parsedMessage && typeof parsedMessage === "object" && "message" in parsedMessage) { - errorMessage = parsedMessage.message; + let errorMessage; + + if (error && typeof error === "object" && "error" in error) { + const nestedError = error.error; + if (typeof nestedError === "string") { + try { + const parsedNestedError = JSON.parse(nestedError); + if (parsedNestedError && typeof parsedNestedError === "object" && "message" in parsedNestedError) { + errorMessage = parsedNestedError.message; + } else { + errorMessage = nestedError; + } + } catch (parseError) { + errorMessage = nestedError; } + } else { + errorMessage = nestedError; } - if (errorMessage && typeof errorMessage === "object" && "message" in errorMessage) { - errorMessage = errorMessage.message; - } - openNotification("error", t("Error uploading file"), errorMessage); - hideLoader(); + } else if (error && typeof error === "object" && "message" in error) { + errorMessage = error.message; } else { - openNotification("error", t("Error uploading file"), t("An unknown error occurred")); - hideLoader(); + errorMessage = t("An unknown error occurred"); } + openNotification("error", t("Error uploading file"), errorMessage || t("An unknown error occurred")); + hideLoader(); } };