Skip to content

Commit

Permalink
Show vue errors with stack as toast
Browse files Browse the repository at this point in the history
  • Loading branch information
simar0at committed Oct 1, 2024
1 parent b1eb3ea commit e17b193
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions plugins/error.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
export default defineNuxtPlugin((nuxtApp) => {
const toastsStore = useToastsStore();
const { addToast } = toastsStore;
// TODO: remove or transform before deploying to production
nuxtApp.hook("app:error", (..._args) => {
console.log(
`app:error: [${_args.length} errors]`,
_args.map((e) => e.message),
);
nuxtApp.hook("app:error", (err) => {
console.log(`app:error`, err instanceof Error ? (err.stack ?? err.message) : "");
});
nuxtApp.hook("vue:error", (..._args) => {
console.log(
`vue:error: [${_args.length} errors]`,
//@ts-expect-error TODO establish proper error typing
_args.map((e) => e.message),
);
nuxtApp.hook("vue:error", (error, _instance, _info) => {
// get the name of the instance/component? info is something like setup function so also helpful.
const errorMessage = {
title: "Error",
description: error instanceof Error ? (error.stack ?? error.message) : "",
type: "foreground",
variant: "negative",
} as const;
console.log(`vue:error`, errorMessage.description);
addToast(errorMessage);
});
nuxtApp.vueApp.config.errorHandler = (..._args) => {
nuxtApp.vueApp.config.errorHandler = (error, _instance, _info) => {
console.log(
`global error handler: [${_args.length} errors]`,
//@ts-expect-error TODO establish proper error typing
_args.map((e) => e.message),
`global error handler`,
error instanceof Error ? (error.stack ?? error.message) : "",
);
};
});

0 comments on commit e17b193

Please sign in to comment.