[에너지 라벨]#임시
- 토큰 만료일때 재처리
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { URLS } from '../api/apiConfig';
|
||||
import { TAxios } from '../api/TAxios';
|
||||
import { types } from './actionTypes';
|
||||
import { getReAuthenticationCode } from './deviceActions';
|
||||
|
||||
/**
|
||||
* PDF를 이미지로 변환 (재시도 로직 포함)
|
||||
@@ -52,7 +53,7 @@ export const convertPdfToImage =
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = null;
|
||||
}
|
||||
|
||||
|
||||
// retCode 체크 (프로젝트 API 규약: 200이어도 retCode로 성공/실패 구분)
|
||||
const retCode = response.headers?.retcode || response.headers?.retCode;
|
||||
|
||||
@@ -79,56 +80,62 @@ export const convertPdfToImage =
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let imageUrl;
|
||||
try {
|
||||
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})`
|
||||
);
|
||||
|
||||
if(response.data.size > 100 && response.data.type === "text/xml"){
|
||||
dispatch(getReAuthenticationCode());
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
let imageUrl;
|
||||
try {
|
||||
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();
|
||||
} 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) => {
|
||||
|
||||
Reference in New Issue
Block a user