You've already forked AstralRinth
forked from didirus/AstralRinth
Error handling (#121)
This commit is contained in:
25
theseus_gui/src/store/notifications.js
Normal file
25
theseus_gui/src/store/notifications.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useNotifications = defineStore('notificationsStore', {
|
||||
state: () => ({
|
||||
notificationsWrapper: null,
|
||||
}),
|
||||
actions: {
|
||||
setNotifs(notifs) {
|
||||
this.notificationsWrapper = notifs
|
||||
},
|
||||
addNotification(notif) {
|
||||
this.notificationsWrapper.addNotification(notif)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export const handleError = (err) => {
|
||||
const notifs = useNotifications()
|
||||
notifs.addNotification({
|
||||
title: 'An error occurred',
|
||||
text: err.message ?? err,
|
||||
type: 'error',
|
||||
})
|
||||
console.error(err)
|
||||
}
|
||||
@@ -2,5 +2,6 @@ import { useSearch } from './search'
|
||||
import { useTheming } from './theme'
|
||||
import { useBreadcrumbs } from './breadcrumbs'
|
||||
import { useLoading } from './loading'
|
||||
import { useNotifications, handleError } from './notifications'
|
||||
|
||||
export { useSearch, useTheming, useBreadcrumbs, useLoading }
|
||||
export { useSearch, useTheming, useBreadcrumbs, useLoading, useNotifications, handleError }
|
||||
|
||||
Reference in New Issue
Block a user