From c4443f2ed1ccd4a023a3230fe6bae29f81b536e2 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Thu, 20 Jul 2023 16:36:33 +0800 Subject: [PATCH] Added error handling and new alerts in DiscoverView --- src/router/index.ts | 10 ++++++++++ src/views/DiscoverView.vue | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/router/index.ts b/src/router/index.ts index 501feda2..c524c1b7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -182,4 +182,14 @@ const router = createRouter({ routes, }); +const errorHandler = (error, to, from) => { + // Handle the error here + console.error(error, to, from); + console.log("XXXXX"); + + // You can also perform additional actions, such as displaying an error message or redirecting the user to a specific page +}; + +router.onError(errorHandler); // Assign the error handler to the router instance + export default router; diff --git a/src/views/DiscoverView.vue b/src/views/DiscoverView.vue index a223f72e..b28f5026 100644 --- a/src/views/DiscoverView.vue +++ b/src/views/DiscoverView.vue @@ -186,6 +186,16 @@ export default class DiscoverView extends Vue { if (response.status !== 200) { const details = await response.text(); + this.$notify( + { + group: "alert", + type: "danger", + title: "Danger Alert", + text: details, + }, + -1, + ); + throw details; } @@ -240,6 +250,16 @@ export default class DiscoverView extends Vue { ); if (response.status !== 200) { + const details = await response.text(); + this.$notify( + { + group: "alert", + type: "danger", + title: "Danger Alert", + text: details, + }, + -1, + ); throw await response.text(); }