🕐 커밋 시간: 2025. 12. 15. 09:38:59 📊 변경 통계: • 총 파일: 3개 • 추가: +30줄 📁 추가된 파일: + com.twin.app.shoptime/src/api/logServerClient.js 📝 수정된 파일: ~ com.twin.app.shoptime/src/api/TLogEvent.js ~ com.twin.app.shoptime/src/views/FeaturedBrandsPanel/FeaturedBrandsPanel.jsx 🔧 주요 변경 내용: • API 서비스 레이어 개선 • 소규모 기능 개선
129 lines
3.1 KiB
JavaScript
129 lines
3.1 KiB
JavaScript
import axios from "axios";
|
|
|
|
import { createQueryString } from "../utils/helperMethods";
|
|
import { getUrl } from "./apiConfig";
|
|
import { DEBUG_LOG_MODE, sendToLogServer } from "./logServerClient";
|
|
|
|
export const TLogEvent = (
|
|
dispatch,
|
|
getState,
|
|
type,
|
|
baseUrl,
|
|
urlParams = {},
|
|
params = {},
|
|
onSuccess,
|
|
onFail,
|
|
totalLogFlag = false
|
|
) => {
|
|
const httpHeader = getState().common.httpHeader;
|
|
const appStatus = getState().common.appStatus;
|
|
const AUTHORIZATION = { headers: { ...httpHeader } };
|
|
|
|
const {
|
|
cntry_cd: cntryCd,
|
|
plat_cd: platCd,
|
|
prod_cd: prodCd,
|
|
lang_cd: deviceLang,
|
|
app_ver: appVersion,
|
|
} = httpHeader;
|
|
const { deviceId: dvcId } = appStatus;
|
|
const deviceEulaFlag = httpHeader["X-Device-Eula"];
|
|
const salesModelCode = httpHeader["X-Device-Model"];
|
|
const dvcTp = "tv";
|
|
|
|
if (typeof window === "object") {
|
|
let url = Array.isArray(baseUrl)
|
|
? getUrl(getState, baseUrl[0])
|
|
: getUrl(getState, baseUrl);
|
|
|
|
if (!url) {
|
|
return;
|
|
}
|
|
|
|
if (type === "get") {
|
|
const _urlparams = createQueryString(urlParams);
|
|
url += _urlparams ? `?${_urlparams}` : "";
|
|
}
|
|
|
|
let model;
|
|
if (totalLogFlag) {
|
|
model = {
|
|
...params,
|
|
countryCode: cntryCd,
|
|
deviceId: dvcId,
|
|
devicePlatformVersion: dvcTp,
|
|
platformCode: platCd,
|
|
platformVersion: prodCd,
|
|
appVersion,
|
|
deviceEulaFlag,
|
|
salesModelCode,
|
|
deviceLang,
|
|
};
|
|
} else {
|
|
model = {
|
|
...params,
|
|
cntryCd,
|
|
dvcId,
|
|
dvcTp,
|
|
platCd,
|
|
prodCd,
|
|
};
|
|
}
|
|
|
|
// ===== DEBUG_LOG_MODE: 로그서버로 데이터 전송 =====
|
|
if (DEBUG_LOG_MODE) {
|
|
sendToLogServer({
|
|
deviceId: dvcId,
|
|
cntryCd,
|
|
platCd,
|
|
prodCd,
|
|
appVersion,
|
|
deviceLang,
|
|
logModel: model,
|
|
apiUrl: url,
|
|
httpMethod: type,
|
|
totalLogFlag,
|
|
});
|
|
}
|
|
|
|
let axiosInstance;
|
|
|
|
switch (type) {
|
|
case "get":
|
|
axiosInstance = axios.get(url, AUTHORIZATION);
|
|
break;
|
|
case "post":
|
|
axiosInstance = axios.post(url, model, AUTHORIZATION);
|
|
|
|
break;
|
|
}
|
|
|
|
if (axiosInstance) {
|
|
axiosInstance
|
|
.then((res) => {
|
|
if (onSuccess) {
|
|
onSuccess(res);
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
const errorMessage = error && error.message ? error.message : '';
|
|
const requestUrl = error.config && error.config.url ? error.config.url : '';
|
|
|
|
// /lgsp/v1/log/recommend.lge 엔드포인트의 XML 오류만 무시
|
|
if ((errorMessage.includes('XML') ||
|
|
errorMessage.includes('요소 없음') ||
|
|
errorMessage.includes('element')) &&
|
|
requestUrl.includes('/lgsp/v1/log/recommend.lge')) {
|
|
console.log('[TLogEvent] XML parsing error ignored for recommend endpoint');
|
|
return; // recommend 엔드포인트의 XML 오류만 무시
|
|
}
|
|
|
|
// 다른 엔드포인트의 오류는 정상 처리
|
|
if (onFail) {
|
|
onFail(error);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|