From 509d17e9885c46af9331666a43eb8766ec72c295 Mon Sep 17 00:00:00 2001 From: jack <jack.su@pollex.com.tw> Date: 星期二, 19 九月 2023 12:11:57 +0800 Subject: [PATCH] Merge branch '滲透' of ssh://dev.pollex.com.tw:29418/pcalife/PAM into 滲透 --- PAMapp/shared/services/httpClient.ts | 39 ++++++++++++++++++++++++++++++++++----- 1 files changed, 34 insertions(+), 5 deletions(-) diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts index e524ddf..08a5b6e 100644 --- a/PAMapp/shared/services/httpClient.ts +++ b/PAMapp/shared/services/httpClient.ts @@ -6,18 +6,35 @@ const notRequireInterceptorErrorUrl = [ '/otp/verify', + // '/otp/sendOtp', '/eService/authenticate', '/login/validate/get_img_code', '/login/validate/verify_img_code', + '/api/access_analysis/insert' ]; +function getBaseUrl(): string { + const baseUrl = process.env.BASE_URL; + if (!baseUrl) { + throw new Error('BASE_URL is not defined in process.env'); + } + // const pattern = /^(https?:\/\/)[\w.-]+(:\d+)?/i; // �����RL撽�� + // if (!pattern.test(baseUrl)) { + // throw new Error('Invalid BASE_URL'); + // } + // 銝�閬���RL嚗�摰歇蝬蝯�RL + return baseUrl; +} export const http = axios.create({ - baseURL: process.env.BASE_URL, + baseURL: getBaseUrl(), // 雿輻�������aseURL withCredentials: true }); +let apiNumber = 0; + http.interceptors.request.use( (config: AxiosRequestConfig) => { + apiNumber += 1; loadingStart(); addHttpHeader(config); return config; @@ -26,11 +43,17 @@ http.interceptors.response.use( (response: AxiosResponse) => { - loadingFinish(); + apiNumber -= 1; + if (apiNumber === 0) { + loadingFinish(); + } return response; }, (error: AxiosError) => { - loadingFinish(); + apiNumber -= 1; + if (apiNumber === 0) { + loadingFinish(); + } showErrorMessageBox(error) return Promise.reject(error); } @@ -38,7 +61,8 @@ function addHttpHeader(config: AxiosRequestConfig): void { config.headers = { - Authorization: 'Bearer ' + localStorage.getItem('id_token') + Authorization: 'Bearer ' + localStorage.getItem('id_token'), + 'content-type': 'application/json' } } @@ -55,8 +79,13 @@ }; function showErrorMessageBox(error: any): void { - // console.log('error', error, error.response); setTimeout(() => { + // NOTE: 甇斤 HOT FIX 憿批��憭望������暹��� dialog [Tomas, 2022/7/20 14:21] + if(error.config.url.includes('/eService/authenticate')) return; + if (error.config.url.includes('/otp/sendOtp')) { + messageBoxService.showErrorMessage('', error); + return + } if (!_.includes(notRequireInterceptorErrorUrl, error.config.url)) { switch (error.response.status) { case 401: -- Gitblit v1.8.0