Add unexpected error util

This commit is contained in:
rijkvanzanten
2020-11-05 16:39:59 -05:00
parent 207d347b80
commit e416fbabff
3 changed files with 24 additions and 2 deletions

View File

@@ -612,6 +612,7 @@
"ITEM_LIMIT_REACHED": "Item limit reached.",
"ITEM_NOT_FOUND": "Item not found.",
"ROUTE_NOT_FOUND": "Not found.",
"UNKNOWN": "Unexpected Error",
"-1": "Couldn't Reach API"
},

View File

@@ -1,7 +1,9 @@
import { useNotificationsStore } from '@/stores/';
import { NotificationRaw } from '@/types';
let store: any;
export function notify(notification: NotificationRaw) {
const notificationsStore = useNotificationsStore();
notificationsStore.add(notification);
if (!store) store = useNotificationsStore();
store.add(notification);
}

View File

@@ -0,0 +1,19 @@
import { useNotificationsStore } from '@/stores/';
import { i18n } from '@/lang';
import { RequestError } from '@/api';
let store: any;
export function unexpectedError(error: Error | RequestError) {
if (!store) store = useNotificationsStore();
const code = (error as RequestError).response?.data?.errors?.[0]?.extensions?.code || 'UNKNOWN';
const message = (error as RequestError).response?.data?.errors?.[0]?.message || error.message || undefined;
store.add({
title: i18n.t(`errors.${code}`),
text: message,
type: 'error',
dialog: true,
});
}