[add] Jhipster base
This commit is contained in:
25
front-end/src/main/webapp/app/config/axios-interceptor.ts
Normal file
25
front-end/src/main/webapp/app/config/axios-interceptor.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import axios from 'axios';
|
||||
import { getBasePath, Storage } from 'react-jhipster';
|
||||
|
||||
import { SERVER_API_URL } from 'app/config/constants';
|
||||
|
||||
const TIMEOUT = 1000000; // 10000
|
||||
const setupAxiosInterceptors = onUnauthenticated => {
|
||||
const onRequestSuccess = config => {
|
||||
config.timeout = TIMEOUT;
|
||||
config.url = `${SERVER_API_URL}${config.url}`;
|
||||
return config;
|
||||
};
|
||||
const onResponseSuccess = response => response;
|
||||
const onResponseError = err => {
|
||||
const status = err.status || err.response.status;
|
||||
if (status === 403 || status === 401) {
|
||||
onUnauthenticated();
|
||||
}
|
||||
return Promise.reject(err);
|
||||
};
|
||||
axios.interceptors.request.use(onRequestSuccess);
|
||||
axios.interceptors.response.use(onResponseSuccess, onResponseError);
|
||||
};
|
||||
|
||||
export default setupAxiosInterceptors;
|
||||
Reference in New Issue
Block a user