🥅 Adds graceful error hadling to widgets

This commit is contained in:
Alicia Sykes
2021-12-13 21:40:13 +00:00
parent 19d3c03001
commit 0a4d021b4e
13 changed files with 148 additions and 79 deletions

View File

@@ -1,3 +1,5 @@
import ProgressBar from 'rsup-progress';
import ErrorHandler from '@/utils/ErrorHandler';
import LoadingAnimation from '@/assets/interface-icons/loader.svg';
const WidgetMixin = {
@@ -13,6 +15,7 @@ const WidgetMixin = {
},
data: () => ({
loading: true, // Indicates current loading status, to display spinner
progress: new ProgressBar({ color: 'var(--progress-bar)' }),
}),
methods: {
/* Overridden by widget component. Re-fetches and renders any external data *
@@ -21,6 +24,21 @@ const WidgetMixin = {
// eslint-disable-next-line no-console
console.log('No update method configured for this widget');
},
/* Called when an error occurs */
error(msg, stackTrace) {
ErrorHandler(msg, stackTrace);
this.$emit('error', msg);
},
/* When a data request update starts, show loader */
startLoading() {
this.loading = true;
this.progress.start();
},
/* When a data request finishes, hide loader */
finishLoading() {
this.loading = false;
setTimeout(() => { this.progress.end(); }, 500);
},
},
mounted() {
// If the mounted function isn't overridden,then hide loader