fix: make sure global error handler handles unrejected promises correctly
continuous-integration/drone/push Build is failing Details

Resolves #2992
This commit is contained in:
kolaente 2023-01-25 15:05:54 +01:00
parent fd4a68daf0
commit 4576da0dd3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 19 additions and 17 deletions

View File

@ -1,38 +1,40 @@
import {i18n} from '@/i18n' import {i18n} from '@/i18n'
import {notify} from '@kyvg/vue3-notification' import {notify} from '@kyvg/vue3-notification'
export const getErrorText = (r) => { export function getErrorText(r): string {
let data = undefined
if (r.response && r.response.data) { if (r?.response?.data) {
if(r.response.data.code) { data = r.response.data
const path = `error.${r.response.data.code}` }
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) const message = i18n.global.t(path)
// If message and path are equal no translation exists for that error code // If message and path are equal no translation exists for that error code
if (path !== message) { if (path !== message) {
return [ return message
r.message,
message,
]
} }
} }
if (r.response.data.message) { if (data.message) {
return [ return data.message
r.message,
r.response.data.message,
]
} }
} }
return [r.message] return r.message
} }
export function error(e, actions = []) { export function error(e, actions = []) {
notify({ notify({
type: 'error', type: 'error',
title: i18n.global.t('error.error'), title: i18n.global.t('error.error'),
text: getErrorText(e), text: [getErrorText(e)],
actions: actions, actions: actions,
}) })
} }
@ -41,7 +43,7 @@ export function success(e, actions = []) {
notify({ notify({
type: 'success', type: 'success',
title: i18n.global.t('error.success'), title: i18n.global.t('error.success'),
text: getErrorText(e), text: [getErrorText(e)],
data: { data: {
actions: actions, actions: actions,
}, },