From ddd21915c81126941fa984116dd725b59402db4f Mon Sep 17 00:00:00 2001 From: rchrist Date: Thu, 18 Apr 2019 18:04:40 +0200 Subject: [PATCH 1/2] added first error dialogs w/o any error specification --- frontend/src/pages/Cache.vue | 6 +++--- frontend/src/pages/Overview.vue | 12 +++++++++--- frontend/src/pages/Profile.vue | 4 +++- frontend/src/pages/StationView.vue | 8 ++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index b89af32..a339e36 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -159,9 +159,9 @@ console.log("POST api/createCache: " + response.statusText); this.$store.commit('cacheCollector/RESET_NEW_CACHE'); this.$router.push({ path: '/overview' }); - }) - .catch((error) => { - }); + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }); } else { // TODO update existing Cache } diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 1616f18..7344d27 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -117,7 +117,9 @@ .then((response) => { console.log("Caches: " + this.caches); this.caches = response.data; - }) + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }) }, addCache() { this.$router.push({path: `/cache`}) @@ -129,7 +131,9 @@ this.$axios.delete('/api/deleteCache', {params: {cacheID: id}}) .then((response) => { this.fetchAllCaches() - }) + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }) }, startCache(cacheID) { const userToken = JSON.parse(localStorage.getItem('userToken')).token; @@ -147,7 +151,9 @@ console.log(stationID); //this.$router.push({path: `/station/${stationID}`}) this.$router.push({path: `/station/${cacheID}/${stationID}`}) - }) + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }) } } } diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 9b13749..735b67d 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -127,7 +127,9 @@ this.$axios.get('/api/getMyCaches', { params: {token}} ) .then((response) => { this.startedCaches = response.data; - }); + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }); }, continueCache(cacheID) { } diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 8b13337..7245dbb 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -85,8 +85,12 @@ const stationView = response.data.find(station => station.id === Number(this.$route.params.id)); console.log(JSON.stringify(stationView)); this.data.station = stationView; - }); - }); + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }); + }).catch((error) => { + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + }); } } } From c690c620e43f8071e49207fbe0ebd18c144c1074 Mon Sep 17 00:00:00 2001 From: rchrist Date: Thu, 18 Apr 2019 22:03:23 +0200 Subject: [PATCH 2/2] updated error handling to see the difference between request errors, response errors and other ones --- frontend/src/pages/Cache.vue | 23 ++++++++++- frontend/src/pages/Overview.vue | 63 ++++++++++++++++++++++++++++-- frontend/src/pages/Profile.vue | 23 ++++++++++- frontend/src/pages/StationView.vue | 46 ++++++++++++++++++++-- frontend/src/pages/ranking.vue | 23 ++++++++++- 5 files changed, 165 insertions(+), 13 deletions(-) diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index a339e36..e3126cf 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -160,8 +160,27 @@ this.$store.commit('cacheCollector/RESET_NEW_CACHE'); this.$router.push({ path: '/overview' }); }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) - }); + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + }) } else { // TODO update existing Cache } diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 7344d27..739ec04 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -118,7 +118,26 @@ console.log("Caches: " + this.caches); this.caches = response.data; }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); }) }, addCache() { @@ -132,7 +151,26 @@ .then((response) => { this.fetchAllCaches() }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); }) }, startCache(cacheID) { @@ -152,7 +190,26 @@ //this.$router.push({path: `/station/${stationID}`}) this.$router.push({path: `/station/${cacheID}/${stationID}`}) }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); }) } } diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 735b67d..ebabd60 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -128,8 +128,27 @@ .then((response) => { this.startedCaches = response.data; }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) - }); + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + }) }, continueCache(cacheID) { } diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 7245dbb..767193d 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -86,11 +86,49 @@ console.log(JSON.stringify(stationView)); this.data.station = stationView; }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) - }); + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + }) }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) - }); + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + }) } } } diff --git a/frontend/src/pages/ranking.vue b/frontend/src/pages/ranking.vue index 6ec447d..04b5acb 100644 --- a/frontend/src/pages/ranking.vue +++ b/frontend/src/pages/ranking.vue @@ -83,8 +83,27 @@ console.log(response.data); this.rankinglist = response.data; }).catch((error) => { - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: error }) - }) + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Error occured due to wrong server request!" + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + }) } } }