Browse Source

refactor(gui): check errors is an array or not

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

6
packages/nc-gui/utils/errorUtils.ts

@ -1,7 +1,7 @@
export async function extractSdkResponseErrorMsg(e: Error & { response: any }) {
if (!e || !e.response) return e.message
let msg
let errors: any[]
let errors: any[] | null = null
if (e.response.data instanceof Blob) {
try {
const parsedData = JSON.parse(await e.response.data.text())
@ -15,8 +15,8 @@ export async function extractSdkResponseErrorMsg(e: Error & { response: any }) {
errors = e.response.data.errors
}
if (errors && errors.length) {
return errors.map((e: any) => e.message).join(', ')
if (Array.isArray(errors) && errors.length) {
return errors.map((e: any) => (e.instancePath ? `${e.instancePath} - ` : '') + e.message).join(', ')
}
return msg || 'Some error occurred'

Loading…
Cancel
Save