2021-08-20 13:38:16 +00:00
|
|
|
import {i18n} from '@/i18n'
|
2022-10-18 13:55:41 +00:00
|
|
|
import {notify} from '@kyvg/vue3-notification'
|
2021-08-25 10:28:29 +00:00
|
|
|
|
2023-01-25 14:05:54 +00:00
|
|
|
export function getErrorText(r): string {
|
|
|
|
let data = undefined
|
|
|
|
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}`
|
2021-08-20 13:38:16 +00:00
|
|
|
const message = i18n.global.t(path)
|
2021-06-23 23:24:57 +00:00
|
|
|
|
|
|
|
// If message and path are equal no translation exists for that error code
|
|
|
|
if (path !== message) {
|
2023-01-25 14:05:54 +00:00
|
|
|
return message
|
2021-06-23 23:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-25 14:05:54 +00:00
|
|
|
if (data.message) {
|
|
|
|
return data.message
|
2021-06-23 23:24:57 +00:00
|
|
|
}
|
2021-06-22 20:41:29 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 14:05:54 +00:00
|
|
|
return r.message
|
2021-06-22 20:41:29 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 13:46:41 +00:00
|
|
|
export function error(e, actions = []) {
|
|
|
|
notify({
|
2021-08-25 10:28:29 +00:00
|
|
|
type: 'error',
|
2021-08-20 13:38:16 +00:00
|
|
|
title: i18n.global.t('error.error'),
|
2023-01-25 14:05:54 +00:00
|
|
|
text: [getErrorText(e)],
|
2021-08-25 10:28:29 +00:00
|
|
|
actions: actions,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-20 13:46:41 +00:00
|
|
|
export function success(e, actions = []) {
|
|
|
|
notify({
|
2021-08-25 10:28:29 +00:00
|
|
|
type: 'success',
|
2021-08-20 13:38:16 +00:00
|
|
|
title: i18n.global.t('error.success'),
|
2023-01-25 14:05:54 +00:00
|
|
|
text: [getErrorText(e)],
|
2021-08-25 10:28:29 +00:00
|
|
|
data: {
|
2020-03-02 20:19:26 +00:00
|
|
|
actions: actions,
|
2021-08-25 10:28:29 +00:00
|
|
|
},
|
|
|
|
})
|
2018-09-08 19:43:16 +00:00
|
|
|
}
|