From 2066bf9e1a39b03dd4abea5921d661a91e78f5be Mon Sep 17 00:00:00 2001 From: Viren Baraiya Date: Wed, 27 Sep 2023 10:11:40 -0700 Subject: [PATCH] Merge pull request #3779 from Young-Zen/ui-fix-validation-error-handling Fix validation error handling in workflow/task editor --- ui/src/pages/definition/SaveTaskDialog.jsx | 9 +++++---- ui/src/pages/definition/SaveWorkflowDialog.jsx | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ui/src/pages/definition/SaveTaskDialog.jsx b/ui/src/pages/definition/SaveTaskDialog.jsx index 7d6808ef94..7b1bc0ce65 100644 --- a/ui/src/pages/definition/SaveTaskDialog.jsx +++ b/ui/src/pages/definition/SaveTaskDialog.jsx @@ -49,11 +49,12 @@ export default function SaveTaskDialog({ onSuccess, onCancel, document }) { }, onError: (err) => { console.log("onerror", err); - let errStr = _.isString(err.body) - ? err.body - : JSON.stringify(err.body, null, 2); + const errObj = JSON.parse(err); + let errStr = errObj.validationErrors && errObj.validationErrors.length > 0 + ? `${errObj.validationErrors[0].message}: ${errObj.validationErrors[0].path}` + : errObj.message; setErrorMsg({ - message: `${TASK_SAVE_FAILED}: ${errStr}`, + message: `${TASK_SAVE_FAILED} ${errStr}`, dismissible: true, }); }, diff --git a/ui/src/pages/definition/SaveWorkflowDialog.jsx b/ui/src/pages/definition/SaveWorkflowDialog.jsx index 53a1cd1d6a..1d2a4d5069 100644 --- a/ui/src/pages/definition/SaveWorkflowDialog.jsx +++ b/ui/src/pages/definition/SaveWorkflowDialog.jsx @@ -81,10 +81,11 @@ export default function SaveWorkflowDialog({ onSuccess, onCancel, document }) { }, onError: (err) => { console.log("onerror", err); - let errStr = _.isString(err.body) - ? err.body - : JSON.stringify(err.body, null, 2); - setErrorMsg(`${WORKFLOW_SAVE_FAILED}: ${errStr}`); + const errObj = JSON.parse(err); + let errStr = errObj.validationErrors && errObj.validationErrors.length > 0 + ? `${errObj.validationErrors[0].message}: ${errObj.validationErrors[0].path}` + : errObj.message; + setErrorMsg(`${WORKFLOW_SAVE_FAILED} ${errStr}`); }, });