From c8708be39dc7d7689f3cf4ec09960e393a7d82e2 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 15 Nov 2020 18:51:30 +0100 Subject: [PATCH] Better offline detection (e.g. if database is offline) --- src/boot/axios.ts | 21 ++++---- src/components/loading/BackendOffline.vue | 46 ------------------ src/layouts/MainLayout.vue | 42 +++++++++------- src/layouts/OutLayout.vue | 5 +- src/pages/Error404.vue | 33 ------------- src/pages/Offline.vue | 59 +++++++++++++++++++++++ src/plugins/user/store/session.ts | 27 +++++------ src/router/routes.ts | 8 ++- 8 files changed, 112 insertions(+), 129 deletions(-) delete mode 100644 src/components/loading/BackendOffline.vue delete mode 100644 src/pages/Error404.vue create mode 100644 src/pages/Offline.vue diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 99b80ee..4742f04 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -3,7 +3,6 @@ import { boot } from 'quasar/wrappers'; import config from '../config'; import { Store } from 'vuex'; import { StateInterface } from 'src/store'; -import { Notify } from 'quasar'; declare module 'vue/types/vue' { interface Vue { @@ -11,7 +10,7 @@ declare module 'vue/types/vue' { } } -export default boot>(({ Vue, store }) => { +export default boot>(({ Vue, store, router }) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access Vue.prototype.$axios = axios; axios.defaults.baseURL = config.baseURL; @@ -30,7 +29,7 @@ export default boot>(({ Vue, store }) => { /*** * Intercept responses * - filter 401 --> logout - * - filter timeout or 502 --> backendOffline + * - filter timeout or 502-504 --> backendOffline */ axios.interceptors.response.use( response => response, @@ -39,17 +38,15 @@ export default boot>(({ Vue, store }) => { const e = error; if ( e.code === 'ECONNABORTED' || - (e.response && e.response.status === 502) + (e.response && e.response.status >= 502 && e.response.status <= 504) ) { - store.commit('session/setOffline', true); - } else if (e.response && e.response.status == 401) { - return store.dispatch('session/clearCurrent'); - } else { - Notify.create({ - type: 'error', - message: 'Eine Aktion konnte nicht durchgeführt werden.', - group: false + return router.push({ + name: 'offline', + query: { redirect: router.currentRoute.fullPath } }); + } else if (e.response && e.response.status == 401) { + if (router.currentRoute.name !== 'login') + return store.dispatch('session/clearCurrent'); } } return Promise.reject(error); diff --git a/src/components/loading/BackendOffline.vue b/src/components/loading/BackendOffline.vue deleted file mode 100644 index 8870022..0000000 --- a/src/components/loading/BackendOffline.vue +++ /dev/null @@ -1,46 +0,0 @@ - - - diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 7701add..e155437 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -1,6 +1,9 @@