MSP-3074 add roles
This commit is contained in:
1 parent
5a29bfc7f6
commit
9c1b859971
36 files changed
+1063
-100
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import {message} from 'antd';
|
||||
import axios, {AxiosError} from 'axios';
|
||||
import {LocalStorage} from "../utils/localStorageUtils.ts";
|
||||
import {getConfigProperty} from "../utils/configUtils.ts";
|
||||
import {MSPError} from "../types";
|
||||
import {routePaths} from "../constants/routes.ts";
|
||||
import {localStorageKeys} from "../constants/localStorageKeys.ts";
|
||||
|
||||
export const apiService = axios.create({
|
||||
timeout: 15000,
|
||||
data: {},
|
||||
});
|
||||
|
||||
apiService.defaults.headers.post['X-APPLICATION-TOKEN'] = getConfigProperty(
|
||||
'APP_TOKEN',
|
||||
import.meta.env.APP_TOKEN,
|
||||
);
|
||||
|
||||
apiService.interceptors.request.use(
|
||||
async (config: any) => {
|
||||
const headerName = LocalStorage.get(localStorageKeys.HEADER_NAME);
|
||||
config.headers[headerName] = LocalStorage.get(localStorageKeys.USER_TOKEN);
|
||||
|
||||
return config;
|
||||
},
|
||||
(error: AxiosError<MSPError>) => Promise.reject(error),
|
||||
);
|
||||
|
||||
apiService.interceptors.response.use(
|
||||
async (response: any) => response,
|
||||
(error: AxiosError<MSPError>) => {
|
||||
if (error.response && error.response.status === 401) {
|
||||
window.location.href = routePaths.home;
|
||||
LocalStorage.clear();
|
||||
}
|
||||
|
||||
if (error.response && error.response.status === 500) {
|
||||
message.error('Внутренняя ошибка сервиса').then();
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user