2021-08-25 12:28:29 +02:00
|
|
|
import {i18n} from '@/i18n/setup'
|
|
|
|
|
|
|
|
export const getErrorText = (r) => {
|
2021-06-22 22:41:29 +02:00
|
|
|
|
2021-06-24 01:24:57 +02:00
|
|
|
if (r.response && r.response.data) {
|
|
|
|
if(r.response.data.code) {
|
|
|
|
const path = `error.${r.response.data.code}`
|
2021-08-25 12:28:29 +02:00
|
|
|
const message = i18n.t(path)
|
2021-06-24 01:24:57 +02:00
|
|
|
|
|
|
|
// If message and path are equal no translation exists for that error code
|
|
|
|
if (path !== message) {
|
|
|
|
return [
|
|
|
|
r.message,
|
|
|
|
message,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r.response.data.message) {
|
|
|
|
return [
|
|
|
|
r.message,
|
|
|
|
r.response.data.message,
|
|
|
|
]
|
|
|
|
}
|
2021-06-22 22:41:29 +02:00
|
|
|
}
|
|
|
|
|
2021-06-24 01:24:57 +02:00
|
|
|
return [r.message]
|
2021-06-22 22:41:29 +02:00
|
|
|
}
|
|
|
|
|
2021-08-25 12:28:29 +02:00
|
|
|
export function error(e, context, actions = []) {
|
|
|
|
context.$notify({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.t('error.error'),
|
|
|
|
text: getErrorText(e),
|
|
|
|
actions: actions,
|
|
|
|
})
|
|
|
|
console.error(e, actions)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function success(e, context, actions = []) {
|
|
|
|
context.$notify({
|
|
|
|
type: 'success',
|
|
|
|
title: i18n.t('error.success'),
|
|
|
|
text: getErrorText(e),
|
|
|
|
data: {
|
2020-03-02 21:19:26 +01:00
|
|
|
actions: actions,
|
2021-08-25 12:28:29 +02:00
|
|
|
},
|
|
|
|
})
|
2018-09-08 21:43:16 +02:00
|
|
|
}
|