[에너지 라벨]#임시

- 토큰 만료일때 재처리
This commit is contained in:
junghoon86.park
2025-11-12 17:41:00 +09:00
parent 2d2b438508
commit 693780298f

View File

@@ -1,6 +1,7 @@
import { URLS } from '../api/apiConfig'; import { URLS } from '../api/apiConfig';
import { TAxios } from '../api/TAxios'; import { TAxios } from '../api/TAxios';
import { types } from './actionTypes'; import { types } from './actionTypes';
import { getReAuthenticationCode } from './deviceActions';
/** /**
* PDF를 이미지로 변환 (재시도 로직 포함) * PDF를 이미지로 변환 (재시도 로직 포함)
@@ -52,7 +53,7 @@ export const convertPdfToImage =
clearTimeout(timeoutId); clearTimeout(timeoutId);
timeoutId = null; timeoutId = null;
} }
// retCode 체크 (프로젝트 API 규약: 200이어도 retCode로 성공/실패 구분) // retCode 체크 (프로젝트 API 규약: 200이어도 retCode로 성공/실패 구분)
const retCode = response.headers?.retcode || response.headers?.retCode; const retCode = response.headers?.retcode || response.headers?.retCode;
@@ -79,56 +80,62 @@ export const convertPdfToImage =
} }
return; return;
} }
let imageUrl; if(response.data.size > 100 && response.data.type === "text/xml"){
try { dispatch(getReAuthenticationCode());
if (response.data instanceof Blob) {
if (response.data.size === 0) {
throw new Error('Invalid image data (empty blob)');
}
imageUrl = URL.createObjectURL(response.data);
} else if (response.data instanceof ArrayBuffer) {
if (response.data.byteLength === 0) {
throw new Error('Invalid image data (empty buffer)');
}
const blob = new Blob([response.data], { type: 'image/png' });
imageUrl = URL.createObjectURL(blob);
} else {
const blob = new Blob([response.data], { type: 'image/png' });
if (blob.size === 0) {
throw new Error('Invalid image data (empty blob)');
}
imageUrl = URL.createObjectURL(blob);
}
console.log(`✅ [EnergyLabel] Conversion successful on attempt ${attempts}:`, pdfUrl);
dispatch({
type: types.CONVERT_PDF_TO_IMAGE_SUCCESS,
payload: { pdfUrl, imageUrl },
});
callback && callback(null, imageUrl);
} catch (error) {
console.error(`❌ [EnergyLabel] Image creation failed on attempt ${attempts}:`, error);
// 이미지 생성 실패도 재시도
if (attempts < maxRetries + 1) {
console.log(
`🔄 [EnergyLabel] Retrying due to image creation error... (${attempts}/${maxRetries + 1})`
);
attemptConversion(); attemptConversion();
} else { return;
console.error( }
`❌ [EnergyLabel] Final failure after ${attempts} attempts (image error):`,
pdfUrl let imageUrl;
); try {
dispatch({ if (response.data instanceof Blob) {
type: types.CONVERT_PDF_TO_IMAGE_FAILURE, if (response.data.size === 0) {
payload: { pdfUrl, error }, throw new Error('Invalid image data (empty blob)');
}); }
callback && callback(error, null); imageUrl = URL.createObjectURL(response.data);
} else if (response.data instanceof ArrayBuffer) {
if (response.data.byteLength === 0) {
throw new Error('Invalid image data (empty buffer)');
}
const blob = new Blob([response.data], { type: 'image/png' });
imageUrl = URL.createObjectURL(blob);
} else {
const blob = new Blob([response.data], { type: 'image/png' });
if (blob.size === 0) {
throw new Error('Invalid image data (empty blob)');
}
imageUrl = URL.createObjectURL(blob);
}
console.log(`✅ [EnergyLabel] Conversion successful on attempt ${attempts}:`, pdfUrl);
dispatch({
type: types.CONVERT_PDF_TO_IMAGE_SUCCESS,
payload: { pdfUrl, imageUrl },
});
callback && callback(null, imageUrl);
} catch (error) {
console.error(`❌ [EnergyLabel] Image creation failed on attempt ${attempts}:`, error);
// 이미지 생성 실패도 재시도
if (attempts < maxRetries + 1) {
console.log(
`🔄 [EnergyLabel] Retrying due to image creation error... (${attempts}/${maxRetries + 1})`
);
attemptConversion();
} else {
console.error(
`❌ [EnergyLabel] Final failure after ${attempts} attempts (image error):`,
pdfUrl
);
dispatch({
type: types.CONVERT_PDF_TO_IMAGE_FAILURE,
payload: { pdfUrl, error },
});
callback && callback(error, null);
}
} }
}
}; };
const onFail = (error) => { const onFail = (error) => {