From e0bb2c26fb05d8d31be26d9802879cb33999b016 Mon Sep 17 00:00:00 2001 From: jangheon Pyo Date: Mon, 8 Jul 2024 16:58:53 +0900 Subject: [PATCH] =?UTF-8?q?[TAxios]=20=EB=B3=B5=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com.twin.app.shoptime/src/api/TAxios.js | 40 +++++++------------------ 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/com.twin.app.shoptime/src/api/TAxios.js b/com.twin.app.shoptime/src/api/TAxios.js index 9ceea620..c8fe3633 100644 --- a/com.twin.app.shoptime/src/api/TAxios.js +++ b/com.twin.app.shoptime/src/api/TAxios.js @@ -6,7 +6,6 @@ import { types } from "../actions/actionTypes"; import { changeAppStatus, changeLocalSettings, - loadingComplete, setShowPopup, setSystemNotice, setSystemTermination, @@ -19,8 +18,6 @@ import { ACTIVE_POPUP } from "../utils/Config"; import * as HelperMethods from "../utils/helperMethods"; import { getUrl, URLS } from "./apiConfig"; -const MAX_RETRIES = 10; -const INITIAL_DELAY = 100; let tokenRefreshing = false; export const setTokenRefreshing = (value) => { console.log("TAxios setTokenRefreshing ", value); @@ -38,7 +35,7 @@ export const TAxios = ( onFail, noTokenRefresh = false ) => { - const checkAccessToken = (retryCount = 0) => { + const checkAccessToken = () => { return new Promise((resolve) => { const accessToken = getState().localSettings.accessToken; if (noTokenRefresh || (!tokenRefreshing && accessToken)) { @@ -47,21 +44,14 @@ export const TAxios = ( if (!accessToken && !tokenRefreshing) { dispatch(getAuthenticationCode()); } - const delay = INITIAL_DELAY * Math.pow(2, retryCount); - HelperMethods.wait(delay).then(() => { - if (retryCount < MAX_RETRIES) { - resolve(checkAccessToken(retryCount + 1)); - } else { - console.error("max retries reached for token refresh"); - onFail(new Error("max retries reached for token refresh")); - resolve(null); - } + HelperMethods.wait(100).then(() => { + resolve(checkAccessToken()); }); } }); }; - const executeRequest = (accessToken, retryCount) => { + const executeRequest = (accessToken) => { const httpHeader = getState().common.httpHeader; const { mbr_no, deviceId } = getState().common.appStatus; const refreshToken = getState().localSettings.refreshToken; @@ -117,8 +107,6 @@ export const TAxios = ( if (baseUrl === URLS.GET_AUTHENTICATION_CODE) { if (res?.data?.retCode !== 0) { console.error("accessToken failed", res.data.retCode); - dispatch(loadingComplete(false)); - dispatch(changeAppStatus({ isAuthenticationComplete: false })); dispatch( setShowPopup(ACTIVE_POPUP.networkErrorPopup, { data: res.data.retCode, @@ -141,25 +129,19 @@ export const TAxios = ( dispatch(getReAuthenticationCode()); } checkAccessToken().then((token) => { - executeRequest(token, retryCount); + executeRequest(token); }); return; } //RefreshToken 만료 if (res?.data?.retCode === 402 || res?.data?.retCode === 501) { - if (retryCount < MAX_RETRIES) { - if (!tokenRefreshing) { - dispatch(getAuthenticationCode()); - } - const delay = INITIAL_DELAY * Math.pow(2, retryCount); - - setTimeout(() => { - checkAccessToken().then((token) => { - executeRequest(token, retryCount + 1); - }); - }, delay); - return; + if (!tokenRefreshing) { + dispatch(getAuthenticationCode()); } + checkAccessToken().then((token) => { + executeRequest(token); + }); + return; } // 602 요청 국가 불일치 if (res?.data?.retCode === 602) {