-
Notifications
You must be signed in to change notification settings - Fork 0
/
axios.manager.ts
58 lines (43 loc) · 1.36 KB
/
axios.manager.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { AuthApi, Configuration, MainApi } from "../api"
import { API_URL } from "./constants/general"
import { setGeneralNetwork } from "./redux/slices/globalSlice";
import axios, { AxiosError, HttpStatusCode } from "axios";
import { store } from "./redux/stores/store";
import { setSnack } from "./utils/utils";
export const ConfigAxios = () => {
axios.defaults.withCredentials = true
axios.interceptors.request.use(
async (config) => {
store.dispatch(setGeneralNetwork(true))
return config
},
(error) => {
Promise.reject(error)
}
)
axios.interceptors.response.use(
(response) => {
store.dispatch(setGeneralNetwork(false))
return response
},
(error: AxiosError) => {
store.dispatch(setGeneralNetwork(false))
if (error?.response?.status === HttpStatusCode.BadGateway) {
setSnack({
title: "Network error",
msg: ["Backend server unreachable"],
type: 'error'
})
return
}
// else handleApiException(error)
return Promise.reject(error);
}
)
}
export const authApi = new AuthApi(new Configuration({
basePath: API_URL()
}))
export const mainApi = new MainApi(new Configuration({
basePath: API_URL()
}))