fix: Improve error handling in document update process

(cherry picked from commit e578513eaf9a470271d11a69f151b29459fc4ff8)
This commit is contained in:
Shariq Ansari 2025-07-28 16:43:46 +05:30 committed by Mergify
parent 1c4dd8a59d
commit 53781cbf1e

View File

@ -27,7 +27,7 @@ export function useDocument(doctype, docname) {
},
onError: (err) => {
triggerOnError(err)
let errorMessage = __('Error updating document')
if (err.exc_type == 'MandatoryError') {
const fieldName = err.messages
.map((msg) => {
@ -35,9 +35,18 @@ export function useDocument(doctype, docname) {
return arr[arr.length - 1].trim()
})
.join(', ')
errorMessage = __('Mandatory field error: {0}', [fieldName])
toast.error(__('Mandatory field error: {0}', [fieldName]))
return
}
toast.error(errorMessage)
err.messages?.forEach((msg) => {
toast.error(msg)
})
if (err.messages?.length === 0) {
toast.error(__('An error occurred while updating the document'))
}
console.error(err)
},
},