mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add unexpected error util
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
19
app/src/utils/unexpected-error.ts
Normal file
19
app/src/utils/unexpected-error.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user