This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/message/index.js
konrad f0498fd767
All checks were successful
continuous-integration/drone/push Build is passing
Add translations (#562)
Reviewed-on: #562
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
2021-06-23 23:24:57 +00:00

47 lines
849 B
JavaScript

export const getErrorText = (r, $t) => {
if (r.response && r.response.data) {
if(r.response.data.code) {
const path = `error.${r.response.data.code}`
const message = $t(path)
// 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,
]
}
}
return [r.message]
}
export default {
error(e, context, $t, actions = []) {
context.$notify({
type: 'error',
title: $t('error.error'),
text: getErrorText(e, $t),
actions: actions,
})
},
success(e, context, $t, actions = []) {
context.$notify({
type: 'success',
title: $t('error.success'),
text: getErrorText(e, $t),
data: {
actions: actions,
},
})
},
}