blob: 04caea12316e9574cc543be73d427cd772eb7ed2 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import Axios from 'axios';
Yoshie Muranaka74c24f12019-12-03 10:45:46 -08002
Yoshie Muranaka6ce1a072019-12-06 14:13:59 -08003const api = Axios.create({
4 withCredentials: true
5});
Yoshie Muranaka74c24f12019-12-03 10:45:46 -08006
Derick Montague227c41a2019-12-20 17:08:59 -06007api.interceptors.response.use(undefined, error => {
8 let response = error.response;
9 // TODO: Provide user with a notification and way to keep system active
10 if (response.status == 401) {
11 window.location = '/login';
12 }
13});
14
Yoshie Muranaka74c24f12019-12-03 10:45:46 -080015export default {
16 get(path) {
17 return api.get(path);
18 },
19 delete(path, payload) {
20 return api.delete(path, payload);
21 },
22 post(path, payload) {
23 return api.post(path, payload);
24 },
25 patch(path, payload) {
26 return api.patch(path, payload);
27 },
28 put(path, payload) {
29 return api.put(path, payload);
30 },
31 all(promises) {
32 return Axios.all(promises);
Yoshie Muranakadc04feb2019-12-04 08:41:22 -080033 }
Yoshie Muranaka74c24f12019-12-03 10:45:46 -080034};