mirror of
https://github.com/directus/directus.git
synced 2026-02-19 10:14:33 -05:00
Add unexpected error util
This commit is contained in:
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