[TAxios] 복구
This commit is contained in:
@@ -6,7 +6,6 @@ import { types } from "../actions/actionTypes";
|
|||||||
import {
|
import {
|
||||||
changeAppStatus,
|
changeAppStatus,
|
||||||
changeLocalSettings,
|
changeLocalSettings,
|
||||||
loadingComplete,
|
|
||||||
setShowPopup,
|
setShowPopup,
|
||||||
setSystemNotice,
|
setSystemNotice,
|
||||||
setSystemTermination,
|
setSystemTermination,
|
||||||
@@ -19,8 +18,6 @@ import { ACTIVE_POPUP } from "../utils/Config";
|
|||||||
import * as HelperMethods from "../utils/helperMethods";
|
import * as HelperMethods from "../utils/helperMethods";
|
||||||
import { getUrl, URLS } from "./apiConfig";
|
import { getUrl, URLS } from "./apiConfig";
|
||||||
|
|
||||||
const MAX_RETRIES = 10;
|
|
||||||
const INITIAL_DELAY = 100;
|
|
||||||
let tokenRefreshing = false;
|
let tokenRefreshing = false;
|
||||||
export const setTokenRefreshing = (value) => {
|
export const setTokenRefreshing = (value) => {
|
||||||
console.log("TAxios setTokenRefreshing ", value);
|
console.log("TAxios setTokenRefreshing ", value);
|
||||||
@@ -38,7 +35,7 @@ export const TAxios = (
|
|||||||
onFail,
|
onFail,
|
||||||
noTokenRefresh = false
|
noTokenRefresh = false
|
||||||
) => {
|
) => {
|
||||||
const checkAccessToken = (retryCount = 0) => {
|
const checkAccessToken = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const accessToken = getState().localSettings.accessToken;
|
const accessToken = getState().localSettings.accessToken;
|
||||||
if (noTokenRefresh || (!tokenRefreshing && accessToken)) {
|
if (noTokenRefresh || (!tokenRefreshing && accessToken)) {
|
||||||
@@ -47,21 +44,14 @@ export const TAxios = (
|
|||||||
if (!accessToken && !tokenRefreshing) {
|
if (!accessToken && !tokenRefreshing) {
|
||||||
dispatch(getAuthenticationCode());
|
dispatch(getAuthenticationCode());
|
||||||
}
|
}
|
||||||
const delay = INITIAL_DELAY * Math.pow(2, retryCount);
|
HelperMethods.wait(100).then(() => {
|
||||||
HelperMethods.wait(delay).then(() => {
|
resolve(checkAccessToken());
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const executeRequest = (accessToken, retryCount) => {
|
const executeRequest = (accessToken) => {
|
||||||
const httpHeader = getState().common.httpHeader;
|
const httpHeader = getState().common.httpHeader;
|
||||||
const { mbr_no, deviceId } = getState().common.appStatus;
|
const { mbr_no, deviceId } = getState().common.appStatus;
|
||||||
const refreshToken = getState().localSettings.refreshToken;
|
const refreshToken = getState().localSettings.refreshToken;
|
||||||
@@ -117,8 +107,6 @@ export const TAxios = (
|
|||||||
if (baseUrl === URLS.GET_AUTHENTICATION_CODE) {
|
if (baseUrl === URLS.GET_AUTHENTICATION_CODE) {
|
||||||
if (res?.data?.retCode !== 0) {
|
if (res?.data?.retCode !== 0) {
|
||||||
console.error("accessToken failed", res.data.retCode);
|
console.error("accessToken failed", res.data.retCode);
|
||||||
dispatch(loadingComplete(false));
|
|
||||||
dispatch(changeAppStatus({ isAuthenticationComplete: false }));
|
|
||||||
dispatch(
|
dispatch(
|
||||||
setShowPopup(ACTIVE_POPUP.networkErrorPopup, {
|
setShowPopup(ACTIVE_POPUP.networkErrorPopup, {
|
||||||
data: res.data.retCode,
|
data: res.data.retCode,
|
||||||
@@ -141,25 +129,19 @@ export const TAxios = (
|
|||||||
dispatch(getReAuthenticationCode());
|
dispatch(getReAuthenticationCode());
|
||||||
}
|
}
|
||||||
checkAccessToken().then((token) => {
|
checkAccessToken().then((token) => {
|
||||||
executeRequest(token, retryCount);
|
executeRequest(token);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//RefreshToken 만료
|
//RefreshToken 만료
|
||||||
if (res?.data?.retCode === 402 || res?.data?.retCode === 501) {
|
if (res?.data?.retCode === 402 || res?.data?.retCode === 501) {
|
||||||
if (retryCount < MAX_RETRIES) {
|
if (!tokenRefreshing) {
|
||||||
if (!tokenRefreshing) {
|
dispatch(getAuthenticationCode());
|
||||||
dispatch(getAuthenticationCode());
|
|
||||||
}
|
|
||||||
const delay = INITIAL_DELAY * Math.pow(2, retryCount);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
checkAccessToken().then((token) => {
|
|
||||||
executeRequest(token, retryCount + 1);
|
|
||||||
});
|
|
||||||
}, delay);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
checkAccessToken().then((token) => {
|
||||||
|
executeRequest(token);
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// 602 요청 국가 불일치
|
// 602 요청 국가 불일치
|
||||||
if (res?.data?.retCode === 602) {
|
if (res?.data?.retCode === 602) {
|
||||||
|
|||||||
Reference in New Issue
Block a user