(config: AxiosRequestConfig)
| 26 | class RequestHttp { |
| 27 | service: AxiosInstance; |
| 28 | public constructor(config: AxiosRequestConfig) { |
| 29 | this.service = axios.create(config); |
| 30 | this.service.interceptors.request.use( |
| 31 | (config: AxiosRequestConfig) => { |
| 32 | const globalStore = GlobalStore(); |
| 33 | config.headers = { |
| 34 | 'Accept-Language': globalStore.language, |
| 35 | ...config.headers, |
| 36 | }; |
| 37 | if (config.headers.CurrentNode == undefined) { |
| 38 | config.headers.CurrentNode = encodeURIComponent( |
| 39 | getOperateNodeOverride() || globalStore.currentNode, |
| 40 | ); |
| 41 | } else { |
| 42 | config.headers.CurrentNode = encodeURIComponent(String(config.headers.CurrentNode)); |
| 43 | } |
| 44 | if ( |
| 45 | config.url === '/core/auth/login' || |
| 46 | config.url === '/core/auth/mfalogin' || |
| 47 | config.url === '/core/auth/passkey/begin' || |
| 48 | config.url === '/core/auth/passkey/finish' |
| 49 | ) { |
| 50 | config.headers.EntranceCode = encodeBase64(globalStore.entrance); |
| 51 | } |
| 52 | const method = (config.method || 'get').toUpperCase(); |
| 53 | const requiresToken = !['GET', 'HEAD', 'OPTIONS', 'TRACE'].includes(method); |
| 54 | if (requiresToken) { |
| 55 | const csrfToken = getCookie('pcsrftoken'); |
| 56 | if (csrfToken) { |
| 57 | config.headers['X-CSRF-Token'] = csrfToken; |
| 58 | globalStore.csrfToken = csrfToken; |
| 59 | } |
| 60 | } |
| 61 | return { |
| 62 | ...config, |
| 63 | } as InternalAxiosRequestConfig<any>; |
| 64 | }, |
| 65 | (error: AxiosError) => { |
| 66 | return Promise.reject(error); |
| 67 | }, |
| 68 | ); |
| 69 | |
| 70 | this.service.interceptors.response.use( |
| 71 | (response: AxiosResponse) => { |
| 72 | const globalStore = GlobalStore(); |
| 73 | const { data } = response; |
| 74 | const authResult = handleAuthResponseCode(data, { showRBACMessage: true }); |
| 75 | if (authResult.handled) { |
| 76 | if (authResult.action === 'return') { |
| 77 | return; |
| 78 | } |
| 79 | return Promise.reject(data); |
| 80 | } |
| 81 | if (data.code == ResultEnum.ERR_XPACK) { |
| 82 | globalStore.isProductPro = false; |
| 83 | window.location.reload(); |
| 84 | return Promise.reject(data); |
| 85 | } |
nothing calls this directly
no test coverage detected