From 7399f0a087f14e0525ed0f891288b2e1650f5f36 Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期一, 19 九月 2022 21:32:45 +0800 Subject: [PATCH] fix#144075: [前台] 顧問帳號已停用,登入後會跳出登入逾時視窗 --- PAMapp/shared/services/httpClient.ts | 28 ++++++++++++++++++++++------ 1 files changed, 22 insertions(+), 6 deletions(-) diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts index 531eda2..c0b08f2 100644 --- a/PAMapp/shared/services/httpClient.ts +++ b/PAMapp/shared/services/httpClient.ts @@ -1,10 +1,12 @@ import { AxiosRequestConfig, AxiosError, AxiosResponse} from 'axios'; -import ErrorMessageBox from '../errorService'; import axios from 'axios'; import _ from 'lodash'; +import messageBoxService from './message-box.service'; + const notRequireInterceptorErrorUrl = [ '/otp/verify', + // '/otp/sendOtp', '/eService/authenticate', '/login/validate/get_img_code', '/login/validate/verify_img_code', @@ -15,8 +17,11 @@ withCredentials: true }); +let apiNumber = 0; + http.interceptors.request.use( (config: AxiosRequestConfig) => { + apiNumber += 1; loadingStart(); addHttpHeader(config); return config; @@ -25,11 +30,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); } @@ -54,18 +65,23 @@ }; 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: - Promise.all([ErrorMessageBox('���暹��'), window.$nuxt.$store.dispatch('localStorage/actionStorageClear')]).then(() => { + Promise.all([messageBoxService.showErrorMessage('���暹��'), window.$nuxt.$store.dispatch('localStorage/actionStorageClear')]).then(() => { _.isEqual(window.$nuxt.$route.name, 'index') ? location.reload() : window.$nuxt.$router.push('/'); }); break; default: - ErrorMessageBox('', error); + messageBoxService.showErrorMessage('', error); break; } } -- Gitblit v1.8.0