chore: simplify getting the error text from an exception
This commit is contained in:
parent
e67088fdb7
commit
9adf1aba89
@ -2,32 +2,19 @@ import {i18n} from '@/i18n'
|
|||||||
import {notify} from '@kyvg/vue3-notification'
|
import {notify} from '@kyvg/vue3-notification'
|
||||||
|
|
||||||
export function getErrorText(r): string {
|
export function getErrorText(r): string {
|
||||||
let data = undefined
|
const data = r?.reason?.response?.data || r?.response?.data
|
||||||
if (r?.response?.data) {
|
|
||||||
data = r.response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r?.reason?.response?.data) {
|
|
||||||
data = r.reason.response.data
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
if(data.code) {
|
|
||||||
const path = `error.${data.code}`
|
|
||||||
const message = i18n.global.t(path)
|
|
||||||
|
|
||||||
// If message and path are equal no translation exists for that error code
|
if (data?.code) {
|
||||||
if (path !== message) {
|
const path = `error.${data.code}`
|
||||||
return message
|
const message = i18n.global.t(path)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.message) {
|
// If message and path are equal no translation exists for that error code
|
||||||
return data.message
|
if (path !== message) {
|
||||||
|
return message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.message
|
return data?.message || r.message
|
||||||
}
|
}
|
||||||
|
|
||||||
export function error(e, actions = []) {
|
export function error(e, actions = []) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user