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 {
|
2023-01-25 17:44:02 +00:00
|
|
|
const data = r?.reason?.response?.data || r?.response?.data
|
2021-06-23 23:24:57 +00:00
|
|
|
|
2023-01-25 17:44:02 +00:00
|
|
|
if (data?.code) {
|
|
|
|
const path = `error.${data.code}`
|
|
|
|
const message = i18n.global.t(path)
|
2021-06-23 23:24:57 +00:00
|
|
|
|
2023-01-25 17:44:02 +00:00
|
|
|
// If message and path are equal no translation exists for that error code
|
|
|
|
if (path !== message) {
|
|
|
|
return message
|
2021-06-23 23:24:57 +00:00
|
|
|
}
|
2021-06-22 20:41:29 +00:00
|
|
|
}
|
2023-07-10 10:20:24 +00:00
|
|
|
|
|
|
|
let message = data?.message || r.message
|
|
|
|
|
|
|
|
if (typeof r.cause?.message !== 'undefined') {
|
|
|
|
message += ' ' + r.cause.message
|
|
|
|
}
|
2021-06-22 20:41:29 +00:00
|
|
|
|
2023-07-10 10:20:24 +00:00
|
|
|
return message
|
2021-06-22 20:41:29 +00:00
|
|
|
}
|
|
|
|
|
2023-03-08 09:51:55 +00:00
|
|
|
export interface Action {
|
|
|
|
title: string,
|
|
|
|
callback: () => void,
|
|
|
|
}
|
|
|
|
|
|
|
|
export function error(e, actions: Action[] = []) {
|
2021-08-20 13:46:41 +00:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-08 09:51:55 +00:00
|
|
|
export function success(e, actions: Action[] = []) {
|
2021-08-20 13:46:41 +00:00
|
|
|
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
|
|
|
}
|