0f94839d
함상기
babylon client fo...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import axios from 'axios';
import VueCookies from 'vue-cookies';
import { refreshToken } from '../service/login'
// axios.defaults.baseURL = 'http://localhost:8080';
// Add a request interceptor
axios.interceptors.request.use(async function (config) {
// Do something before request is sent
config.headers.Authorization = "Bearer " + VueCookies.get('token');
config.headers.REFRESH_TOKEN = VueCookies.get('refresh_token');
console.log(config);
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, async function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
console.log('에러일 경우', error.config);
const errorAPI = error.config;
if((error.response.status===401 || error.response.status===405) && errorAPI.retry===undefined){
errorAPI.retry = true;
console.log('토큰이 이상한 오류일 경우');
await refreshToken();
return await axios(errorAPI);
}
return Promise.reject(error);
});
export default axios;
|