Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 1 | import Axios from 'axios'; |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 2 | |
Yoshie Muranaka | 6ce1a07 | 2019-12-06 14:13:59 -0800 | [diff] [blame] | 3 | const api = Axios.create({ |
| 4 | withCredentials: true |
| 5 | }); |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 6 | |
Derick Montague | 227c41a | 2019-12-20 17:08:59 -0600 | [diff] [blame^] | 7 | api.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 Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 15 | export 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 Muranaka | dc04feb | 2019-12-04 08:41:22 -0800 | [diff] [blame] | 33 | } |
Yoshie Muranaka | 74c24f1 | 2019-12-03 10:45:46 -0800 | [diff] [blame] | 34 | }; |