🥅 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

@@ -8,7 +8,6 @@
<script>
import axios from 'axios';
import WidgetMixin from '@/mixins/WidgetMixin';
import ErrorHandler from '@/utils/ErrorHandler';
import { widgetApiEndpoints } from '@/utils/defaults';
export default {
@@ -56,6 +55,7 @@ export default {
methods: {
/* Extends mixin, and updates data. Called by parent component */
update() {
this.startLoading();
this.fetchData();
},
/* Make GET request to Jokes API endpoint */
@@ -63,12 +63,15 @@ export default {
axios.get(this.endpoint)
.then((response) => {
if (response.data.error) {
ErrorHandler('No matching jokes returned', response.data.additionalInfo);
this.error('No matching jokes returned', response.data.additionalInfo);
}
this.processData(response.data);
})
.catch((dataFetchError) => {
ErrorHandler('Unable to fetch any jokes', dataFetchError);
this.error('Unable to fetch any jokes', dataFetchError);
})
.finally(() => {
this.finishLoading();
});
},
/* Assign data variables to the returned data */