From a5cea7883a11119b9f136a2dbb151cb1d2328468 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 22 Feb 2023 02:59:17 +0530 Subject: [PATCH] feat: extract validation error and combine if found Signed-off-by: Pranav C --- packages/nc-gui/utils/errorUtils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui/utils/errorUtils.ts b/packages/nc-gui/utils/errorUtils.ts index 6601b5b1dc..ff805aef2e 100644 --- a/packages/nc-gui/utils/errorUtils.ts +++ b/packages/nc-gui/utils/errorUtils.ts @@ -1,14 +1,23 @@ export async function extractSdkResponseErrorMsg(e: Error & { response: any }) { if (!e || !e.response) return e.message let msg + let errors: any[] if (e.response.data instanceof Blob) { try { - msg = JSON.parse(await e.response.data.text()).msg + const parsedData = JSON.parse(await e.response.data.text()) + msg = parsedData.msg + errors = parsedData.errors } catch { msg = 'Some internal error occurred' } } else { msg = e.response.data.msg || e.response.data.message || 'Some internal error occurred' + errors = e.response.data.errors } + + if (errors && errors.length) { + return errors.map((e: any) => e.message).join(', ') + } + return msg || 'Some error occurred' }