diff options
| author | Pitu <[email protected]> | 2021-01-04 01:04:20 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2021-01-04 01:04:20 +0900 |
| commit | fcd39dc550dec8dbcb8325e07e938c5024cbc33d (patch) | |
| tree | f41acb4e0d5fd3c3b1236fe4324b3fef9ec6eafe /src/site/plugins/axios.js | |
| parent | Create FUNDING.yml (diff) | |
| parent | chore: update todo (diff) | |
| download | host.fuwn.me-fcd39dc550dec8dbcb8325e07e938c5024cbc33d.tar.xz host.fuwn.me-fcd39dc550dec8dbcb8325e07e938c5024cbc33d.zip | |
Merge branch 'dev'
Diffstat (limited to 'src/site/plugins/axios.js')
| -rw-r--r-- | src/site/plugins/axios.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/site/plugins/axios.js b/src/site/plugins/axios.js new file mode 100644 index 0000000..1c54488 --- /dev/null +++ b/src/site/plugins/axios.js @@ -0,0 +1,32 @@ +export default function({ $axios, store }) { + $axios.setHeader('accept', 'application/vnd.chibisafe.json'); + + $axios.onRequest(config => { + if (store.state.auth.token) { + config.headers.common.Authorization = `bearer ${store.state.auth.token}`; + } + }); + + $axios.onError(error => { + if (process.env.NODE_ENV !== 'production') console.error('[AXIOS Error]', error); + if (process.browser) { + 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'); + } */ + } + }); +} |