From c690c620e43f8071e49207fbe0ebd18c144c1074 Mon Sep 17 00:00:00 2001 From: rchrist Date: Thu, 18 Apr 2019 22:03:23 +0200 Subject: [PATCH] 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, }); + }) } } }