Browse Source

feat: extract validation error and combine if found

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5174/head
Pranav C 2 years ago
parent
commit
a5cea7883a
  1. 11
      packages/nc-gui/utils/errorUtils.ts

11
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'
}

Loading…
Cancel
Save