Skip to content

Commit

Permalink
Fix #623 Add global error handling toaster
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienVig committed Feb 8, 2024
1 parent 9670c44 commit 5499973
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion discojs/discojs-core/src/client/event_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class WebSocketServer implements EventConnection {

return await new Promise((resolve, reject) => {
ws.onerror = (err: isomorphic.ErrorEvent) =>
reject(new Error(`connecting server: ${err.message}`)) // eslint-disable-line @typescript-eslint/restrict-template-expressions
reject(new Error(`Server unreachable: ${err.message}`)) // eslint-disable-line @typescript-eslint/restrict-template-expressions
ws.onopen = () => resolve(server)
})
}
Expand Down
18 changes: 17 additions & 1 deletion web-client/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import VueApexCharts from 'vue3-apexcharts'
import Toaster from '@meforma/vue-toaster'
import { createToaster, Toaster } from '@meforma/vue-toaster'

import App from '@/components/App.vue'
import { router } from '@/router'
Expand All @@ -18,6 +18,22 @@ tf.ready()

// create vue app
const app = createApp(App)

// Global error handler
app.config.errorHandler = (err, instance, info) => {
if (err instanceof TypeError) {
// Implementation bug
const toaster = createToaster({ duration: 5000 })
toaster.error('Sorry, something went wrong on our side. Please reach out on slack.')
console.error(err, instance, info)
} else {
// Unknown error
const toaster = createToaster({ duration: 5000 })
toaster.error('Something went wrong. Please try again later or reach out on slack.')
console.error(err, instance, info)
}
}

const pinia = createPinia()
const i18n = createCustomI18n()
app
Expand Down
10 changes: 5 additions & 5 deletions web-client/src/store/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import { shallowRef } from 'vue'
import { Map } from 'immutable'

import { useToaster } from '@/composables/toaster'
import { TaskID, Task, fetchTasks } from '@epfml/discojs'

import { CONFIG } from '@/config'
Expand All @@ -22,10 +22,10 @@ export const useTasksStore = defineStore('tasks', () => {
const tasks = await fetchTasks(CONFIG.serverUrl)
tasks.forEach(addTask)
} catch (e) {
console.error(
'Fetching of tasks failed with error',
e instanceof Error ? e.message : e.toString()
)
console.error('Fetching of tasks failed with error',
e instanceof Error ? e.message : e.toString())
const toaster = useToaster()
toaster.error('The server is unreachable. \n Please try again later or reach out on slack.')
}
}

Expand Down

0 comments on commit 5499973

Please sign in to comment.