2024-04-25 16:01:08: merge [main:7f9a52684105c7ff0a068812245c462ceb6d553e];

This commit is contained in:
txix committed 2024-04-25 16:01:08 +03:00
1 parent 5a5f104174
commit a31c44eb7b
121 files changed
+14802 -84

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import { message } from 'antd'
import axios, { AxiosError } from 'axios'
import { localStorageKeys } from '@constants/localStorageKeys.ts'
import { getConfigProperty } from '@utils/configUtils.ts'
import { LocalStorage } from '@utils/localStorageUtils.ts'
import { routePaths } from '@routes/routePaths.ts'
import { MSPError } from '@type/index.ts'
export const apiService = axios.create({
timeout: 15000,
data: {}
})
apiService.defaults.headers.post['X-APPLICATION-TOKEN'] = getConfigProperty(
'APP_TOKEN',
import.meta.env.VITE_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>) => {
console.error(error)
if (error.response && error.response.status === 401) {
LocalStorage.clear()
message.error('Ваша сессия истекла"').then()
LocalStorage.set('redirectUrl', location.pathname)
window.location.href = routePaths.login
}
if (error.response && error.response.status >= 500) {
message
.error('Внутренняя ошибка сервиса, попробуйте повторить запрос')
.then()
}
return Promise.reject(error)
}
)