aboutsummaryrefslogtreecommitdiff
path: root/src/site/plugins/axios.js
blob: cc6d98e1b496263e1a191c2b0535938dc9167e90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.onError(error => {
		if (process.env.development) console.error('[AXIOS Error]', error);
		if (process.browser) {
			store.dispatch('alert', {
				text: error.response.data.message,
				error: true
			});
		}
	});
}