1import Axios from 'axios'; 2import router from '../router'; 3 4const api = Axios.create({ 5 withCredentials: true 6}); 7 8api.interceptors.response.use(undefined, error => { 9 let response = error.response; 10 11 // TODO: Provide user with a notification and way to keep system active 12 if (response.status == 401) { 13 if (response.config.url != '/login') { 14 window.location = '/login'; 15 } 16 } 17 18 if (response.status == 403) { 19 router.push({ name: 'unauthorized' }); 20 } 21 22 return Promise.reject(error); 23}); 24 25export default { 26 get(path) { 27 return api.get(path); 28 }, 29 delete(path, payload) { 30 return api.delete(path, payload); 31 }, 32 post(path, payload) { 33 return api.post(path, payload); 34 }, 35 patch(path, payload) { 36 return api.patch(path, payload); 37 }, 38 put(path, payload) { 39 return api.put(path, payload); 40 }, 41 all(promises) { 42 return Axios.all(promises); 43 } 44}; 45