From 9adf1aba895a02f416148ddf8b6925689d6e2687 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 25 Jan 2023 18:44:02 +0100 Subject: [PATCH] chore: simplify getting the error text from an exception --- src/message/index.ts | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/message/index.ts b/src/message/index.ts index 4e462f75c..38d788a2a 100644 --- a/src/message/index.ts +++ b/src/message/index.ts @@ -2,32 +2,19 @@ import {i18n} from '@/i18n' import {notify} from '@kyvg/vue3-notification' 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}` - const message = i18n.global.t(path) + const data = r?.reason?.response?.data || r?.response?.data - // If message and path are equal no translation exists for that error code - if (path !== message) { - return message - } - } + if (data?.code) { + const path = `error.${data.code}` + const message = i18n.global.t(path) - if (data.message) { - return data.message + // If message and path are equal no translation exists for that error code + if (path !== message) { + return message } } - return r.message + return data?.message || r.message } export function error(e, actions = []) {