[TAxios] 복구

This commit is contained in:
jangheon Pyo
2024-07-08 16:58:53 +09:00
parent c3ccad605f
commit e0bb2c26fb

View File

@@ -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) {