From 48292c4f81c98d8c680660b175aa658a986687d0 Mon Sep 17 00:00:00 2001 From: bach Date: Tue, 21 Sep 2021 11:05:29 +0200 Subject: [PATCH] js test with axios interceptors --- .../custom/materiotheme/vuejs/api/ma-axios.js | 16 ++++++++++++++++ .../custom/materiotheme/vuejs/api/rest-axios.js | 14 ++++++++++++++ .../vuejs/components/Content/Card.vue | 2 +- .../materiotheme/vuejs/components/cardMixins.js | 2 +- .../materiotheme/vuejs/store/modules/search.js | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/web/themes/custom/materiotheme/vuejs/api/ma-axios.js b/web/themes/custom/materiotheme/vuejs/api/ma-axios.js index d806e397..cd28d266 100644 --- a/web/themes/custom/materiotheme/vuejs/api/ma-axios.js +++ b/web/themes/custom/materiotheme/vuejs/api/ma-axios.js @@ -4,6 +4,22 @@ import axios from 'axios' // console.log('drupalSettings', drupalSettings) +// axios.interceptors.response.use( +// response => { +// // console.log('ma-axios interceptor response', response) +// return Promise.resolve(response) +// // return response +// }, +// error => { +// const { status } = error.response +// console.warn('error in ma-axios response interceptor, status:', status) +// if (status === 403) { +// window.location = '/' +// } +// return Promise.reject(error) +// } +// ) + const MA = axios.create({ baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix, withCredentials: true, diff --git a/web/themes/custom/materiotheme/vuejs/api/rest-axios.js b/web/themes/custom/materiotheme/vuejs/api/rest-axios.js index dce4391c..e0cc5c5a 100644 --- a/web/themes/custom/materiotheme/vuejs/api/rest-axios.js +++ b/web/themes/custom/materiotheme/vuejs/api/rest-axios.js @@ -5,6 +5,20 @@ import axios from 'axios' // console.log('drupalSettings', drupalSettings) // console.log('window.location.origin', window.location.origin) +// axios.interceptors.response.use( +// response => { +// return Promise.resolve(response) +// }, +// error => { +// const { status } = error.response +// console.warn('error in rest-axios', status) +// if (status === 403) { +// window.location = '/' +// } +// return Promise.reject(error) +// } +// ) + const REST = axios.create({ baseURL: window.location.origin + '/' + drupalSettings.path.pathPrefix, withCredentials: true, diff --git a/web/themes/custom/materiotheme/vuejs/components/Content/Card.vue b/web/themes/custom/materiotheme/vuejs/components/Content/Card.vue index 7aa3f634..33868d23 100644 --- a/web/themes/custom/materiotheme/vuejs/components/Content/Card.vue +++ b/web/themes/custom/materiotheme/vuejs/components/Content/Card.vue @@ -133,7 +133,7 @@ export default { } }, beforeMount () { - console.log(this.item.id, this.samples) + // console.log(this.item.id, this.samples) }, methods: { ...mapActions({ diff --git a/web/themes/custom/materiotheme/vuejs/components/cardMixins.js b/web/themes/custom/materiotheme/vuejs/components/cardMixins.js index fd831abb..cccfa4c4 100644 --- a/web/themes/custom/materiotheme/vuejs/components/cardMixins.js +++ b/web/themes/custom/materiotheme/vuejs/components/cardMixins.js @@ -3,7 +3,7 @@ export default { directives: { lazy: { bind (figure, binding) { - console.log('directive lazy bind', figure, binding) + // console.log('directive lazy bind', figure, binding) // show only the first image if (binding.value === 0) { const img = figure.querySelector('img:not(.blank)') diff --git a/web/themes/custom/materiotheme/vuejs/store/modules/search.js b/web/themes/custom/materiotheme/vuejs/store/modules/search.js index 3e4311ae..45b22d07 100644 --- a/web/themes/custom/materiotheme/vuejs/store/modules/search.js +++ b/web/themes/custom/materiotheme/vuejs/store/modules/search.js @@ -169,6 +169,7 @@ export default { }) .catch((error) => { console.warn('Issue with getResults', error) + // window.location.reload() Promise.reject(error) }) },