blob: 4918d8047f16aa484ca041edca666c05b8cca7a3 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import Axios from 'axios';
Derick Montague126eaab2019-12-23 13:33:52 -06002import router from '../router';
Yoshie Muranaka74c24f12019-12-03 10:45:46 -08003
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -08004const api = Axios.create({
5 withCredentials: true
6});
Yoshie Muranaka74c24f12019-12-03 10:45:46 -08007
Derick Montague227c41a2019-12-20 17:08:59 -06008api.interceptors.response.use(undefined, error => {
9 let response = error.response;
Derick Montague126eaab2019-12-23 13:33:52 -060010
Derick Montague227c41a2019-12-20 17:08:59 -060011 // TODO: Provide user with a notification and way to keep system active
12 if (response.status == 401) {
13 window.location = '/login';
14 }
Derick Montague126eaab2019-12-23 13:33:52 -060015
16 if (response.status == 403) {
17 router.push({ name: 'unauthorized' });
18 }
Derick Montague227c41a2019-12-20 17:08:59 -060019});
20
Yoshie Muranaka74c24f12019-12-03 10:45:46 -080021export default {
22 get(path) {
23 return api.get(path);
24 },
25 delete(path, payload) {
26 return api.delete(path, payload);
27 },
28 post(path, payload) {
29 return api.post(path, payload);
30 },
31 patch(path, payload) {
32 return api.patch(path, payload);
33 },
34 put(path, payload) {
35 return api.put(path, payload);
36 },
37 all(promises) {
38 return Axios.all(promises);
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080039 }
Yoshie Muranaka74c24f12019-12-03 10:45:46 -080040};