add a global error handler
This commit is contained in:
35
src/main.ts
35
src/main.ts
@@ -1,5 +1,5 @@
|
|||||||
import { createPinia } from "pinia";
|
import { createPinia } from "pinia";
|
||||||
import { createApp } from "vue";
|
import { App as VueApp, ComponentPublicInstance, createApp } from "vue";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
import "./registerServiceWorker";
|
import "./registerServiceWorker";
|
||||||
import router from "./router";
|
import router from "./router";
|
||||||
@@ -145,11 +145,38 @@ library.add(
|
|||||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||||
import Camera from "simple-vue-camera";
|
import Camera from "simple-vue-camera";
|
||||||
|
|
||||||
createApp(App)
|
// Can trigger this with a 'throw' inside some top-level function, eg. on the HomeView
|
||||||
|
function setupGlobalErrorHandler(app: VueApp) {
|
||||||
|
// @ts-expect-error 'cause we cannot see why config is not defined
|
||||||
|
app.config.errorHandler = (
|
||||||
|
err: Error,
|
||||||
|
instance: ComponentPublicInstance | null,
|
||||||
|
info: string,
|
||||||
|
) => {
|
||||||
|
console.error(
|
||||||
|
"Global Error Handler. Info:",
|
||||||
|
info,
|
||||||
|
"Error:",
|
||||||
|
err,
|
||||||
|
"Instance:",
|
||||||
|
instance,
|
||||||
|
);
|
||||||
|
// Want to show a nice notiwind notification but can't figure out how.
|
||||||
|
alert(
|
||||||
|
(err.message || "Something bad happened") +
|
||||||
|
" - Try reloading or restarting the app.",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const app = createApp(App)
|
||||||
.component("fa", FontAwesomeIcon)
|
.component("fa", FontAwesomeIcon)
|
||||||
.component("camera", Camera)
|
.component("camera", Camera)
|
||||||
.use(createPinia())
|
.use(createPinia())
|
||||||
.use(VueAxios, axios)
|
.use(VueAxios, axios)
|
||||||
.use(router)
|
.use(router)
|
||||||
.use(Notifications)
|
.use(Notifications);
|
||||||
.mount("#app");
|
|
||||||
|
setupGlobalErrorHandler(app);
|
||||||
|
|
||||||
|
app.mount("#app");
|
||||||
|
|||||||
Reference in New Issue
Block a user