aboutsummaryrefslogtreecommitdiff
path: root/src/site/plugins/axios.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2019-04-24 08:36:47 +0000
committerPitu <[email protected]>2019-04-24 08:36:47 +0000
commitab0839f1f50fcb477476871ca267a004c8fd35e4 (patch)
treee1c3e4314123e3e66645e5766da7d3d41e75a8fd /src/site/plugins/axios.js
parentRefactor a bit since we globally catch API exceptions (diff)
downloadhost.fuwn.me-ab0839f1f50fcb477476871ca267a004c8fd35e4.tar.xz
host.fuwn.me-ab0839f1f50fcb477476871ca267a004c8fd35e4.zip
Globally catch exceptions
Diffstat (limited to 'src/site/plugins/axios.js')
-rw-r--r--src/site/plugins/axios.js35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/site/plugins/axios.js b/src/site/plugins/axios.js
index 5a169b2..cc6d98e 100644
--- a/src/site/plugins/axios.js
+++ b/src/site/plugins/axios.js
@@ -1,29 +1,18 @@
-/*
-import Vue from 'vue';
-import axios from 'axios';
-import VueAxios from 'vue-axios';
-
-Vue.use(VueAxios, axios);
-Vue.axios.defaults.headers.common.Accept = 'application/vnd.lolisafe.json';
-*/
-
-export default function({ $axios, redirect }) {
+export default function({ $axios, store }) {
+ $axios.setHeader('accept', 'application/vnd.lolisafe.json');
$axios.onRequest(config => {
- console.log(`Making request to > /${config.url}`);
+ if (store.state.token) {
+ config.headers.common['Authorization'] = `bearer ${store.state.token}`;
+ }
});
- $axios.setHeader('accept', 'application/vnd.lolisafe.json');
$axios.onError(error => {
- // console.log('=====');
- console.log(error);
- // console.log('=====');
- /*
- $toast.open({
- duration: 2500,
- message: 'testing',
- position: 'is-bottom',
- type: error ? 'is-danger' : 'is-success'
- });
- */
+ if (process.env.development) console.error('[AXIOS Error]', error);
+ if (process.browser) {
+ store.dispatch('alert', {
+ text: error.response.data.message,
+ error: true
+ });
+ }
});
}