aboutsummaryrefslogtreecommitdiff
path: root/src/site/plugins/axios.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/site/plugins/axios.js')
-rw-r--r--src/site/plugins/axios.js34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/site/plugins/axios.js b/src/site/plugins/axios.js
index cc6d98e..98bec5c 100644
--- a/src/site/plugins/axios.js
+++ b/src/site/plugins/axios.js
@@ -1,18 +1,32 @@
-export default function({ $axios, store }) {
+export default function ({ $axios, store }) {
$axios.setHeader('accept', 'application/vnd.lolisafe.json');
- $axios.onRequest(config => {
- if (store.state.token) {
- config.headers.common['Authorization'] = `bearer ${store.state.token}`;
+
+ $axios.onRequest((config) => {
+ if (store.state.auth.token) {
+ config.headers.common.Authorization = `bearer ${store.state.auth.token}`;
}
});
- $axios.onError(error => {
- if (process.env.development) console.error('[AXIOS Error]', error);
+ $axios.onError((error) => {
+ if (process.env.NODE_ENV !== 'production') console.error('[AXIOS Error]', error);
if (process.browser) {
- store.dispatch('alert', {
- text: error.response.data.message,
- error: true
- });
+ if (process.env.NODE_ENV !== 'production') {
+ if (error.response?.data?.message) {
+ store.dispatch('alert/set', {
+ text: error.response.data.message,
+ error: true
+ });
+ } else {
+ store.dispatch('alert/set', {
+ text: `[AXIOS]: ${error.message}`,
+ error: true
+ });
+ }
+ }
+
+ /* if (error.response?.data?.message.indexOf('Token expired') !== -1) {
+ store.dispatch('auth/logout');
+ } */
}
});
}