Skip to content

Commit 88c7da2

Browse files
committed
chore : API 로깅 강화
1 parent 0f68f47 commit 88c7da2

File tree

3 files changed

+59
-63
lines changed

3 files changed

+59
-63
lines changed

apps/Admission-LTS/src/apis/pdfLogging/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IPdfPreviewFailedRequest, IPdfPreviewSuccessRequest } from './types';
1+
import type { IPdfPreviewFailedRequest, IPdfPreviewSuccessRequest, IClientErrorRequest } from './types';
22

33
// PDF 미리보기 성공 로그를 Meerkat에 전송 (에러 발생 시 메인 애플리케이션에 영향 없음)
44
export const sendPdfPreviewSuccess = async (data: IPdfPreviewSuccessRequest) => {
@@ -27,3 +27,17 @@ export const sendPdfPreviewFailed = async (data: IPdfPreviewFailedRequest) => {
2727
console.error('PDF preview failed logging failed:', error);
2828
}
2929
};
30+
31+
// 클라이언트 에러를 Meerkat에 전송 (에러 발생 시 메인 애플리케이션에 영향 없음)
32+
export const sendClientError = async (data: IClientErrorRequest) => {
33+
try {
34+
await fetch('https://meeeeercat.ncloud.sbs/v1/error/client', {
35+
method: 'POST',
36+
headers: { 'Content-Type': 'application/json' },
37+
body: JSON.stringify(data),
38+
});
39+
} catch (error) {
40+
// 로깅 실패해도 무시 (메인 애플리케이션에 영향 없음)
41+
console.error('Client error logging failed:', error);
42+
}
43+
};

apps/Admission-LTS/src/apis/pdfLogging/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,15 @@ export interface IPdfPreviewFailedRequest {
88
sessionId: string;
99
errorMessage: string;
1010
}
11+
12+
export interface IClientErrorRequest {
13+
sessionId: string;
14+
pageType: 'ADMIN' | 'USER';
15+
errorCategory: string;
16+
errorCode: string;
17+
message: string;
18+
stackTrace?: string;
19+
pageUrl: string;
20+
componentName: string;
21+
userAction?: string;
22+
}

apps/Admission-LTS/src/pages/applicationCheck/ApplicationPreview.tsx

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ import { sendPdfPreviewSuccess, sendPdfPreviewFailed, sendClientError } from '..
77
import { useApplicationData } from '@entry/ui';
88
import { convertGradeToScore } from '../../hooks';
99
import { toast } from 'react-toastify';
10-
import { Document, Page, pdfjs } from 'react-pdf';
11-
import workerUrl from 'pdfjs-dist/build/pdf.worker.min.js?url';
12-
13-
// PDF worker 설정을 컴포넌트 외부에서 초기화
14-
pdfjs.GlobalWorkerOptions.workerSrc = workerUrl;
1510

1611
export const ApplicationPreview = () => {
1712
const [isLoading, setIsLoading] = useState<boolean>(false);
1813
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
19-
const [numPages, setNumPages] = useState<number | null>(null);
2014
const hasFetched = useRef(false);
15+
const iframeRef = useRef<HTMLIFrameElement>(null);
2116

2217
const formatDate = (arr: (number|string)[], graduationType: string) => {
2318
// 검정고시는 null 반환
@@ -360,46 +355,30 @@ export const ApplicationPreview = () => {
360355
</NoticeText>
361356
<ApplicationContainer>
362357
{pdfUrl ? (
363-
<PdfViewport>
364-
<Document
365-
file={pdfUrl}
366-
loading={<Text color={colors.gray[400]}>PDF 로딩중...</Text>}
367-
error={<Text color={colors.gray[400]}>PDF 로딩 실패</Text>}
368-
onLoadError={(error) => {
369-
console.error('PDF 로딩 오류:', error);
370-
toast.error('PDF 로딩 실패');
358+
<PdfIframe
359+
ref={iframeRef}
360+
src={pdfUrl}
361+
title="PDF 미리보기"
362+
onLoad={() => {
363+
console.log('PDF 로딩 완료');
364+
}}
365+
onError={(e) => {
366+
console.error('PDF 로딩 오류:', e);
367+
toast.error('PDF 로딩 실패');
371368

372-
// PDF 렌더링 오류를 클라이언트 에러로 전송
373-
sendClientError({
374-
sessionId: sessionIdRef.current,
375-
pageType: 'USER',
376-
errorCategory: 'PDF_RENDER_ERROR',
377-
errorCode: 'ERR_PDF_LOAD',
378-
message: error?.message || 'PDF 렌더링 실패',
379-
stackTrace: error?.stack,
380-
pageUrl: window.location.pathname,
381-
componentName: 'ApplicationPreview',
382-
userAction: 'PDF_PREVIEW',
383-
});
384-
}}
385-
onLoadSuccess={(info: { numPages: number }) => setNumPages(info.numPages)}
386-
options={{
387-
standardFontDataUrl: 'https://unpkg.com/[email protected]/standard_fonts/',
388-
cMapUrl: 'https://unpkg.com/[email protected]/cmaps/',
389-
cMapPacked: true,
390-
}}
391-
>
392-
{Array.from(new Array(numPages || 0), (_el, index) => (
393-
<Page
394-
key={`page_${index + 1}`}
395-
pageNumber={index + 1}
396-
width={794}
397-
renderTextLayer={false}
398-
renderAnnotationLayer={false}
399-
/>
400-
))}
401-
</Document>
402-
</PdfViewport>
369+
// PDF 렌더링 오류를 클라이언트 에러로 전송
370+
sendClientError({
371+
sessionId: sessionIdRef.current,
372+
pageType: 'USER',
373+
errorCategory: 'PDF_RENDER_ERROR',
374+
errorCode: 'ERR_PDF_LOAD',
375+
message: 'PDF iframe 로딩 실패',
376+
pageUrl: window.location.pathname,
377+
componentName: 'ApplicationPreview',
378+
userAction: 'PDF_PREVIEW',
379+
});
380+
}}
381+
/>
403382
) : (
404383
<Text color={colors.gray[400]}>PDF를 불러올 수 없습니다.</Text>
405384
)}
@@ -420,29 +399,20 @@ const Container = styled.div`
420399
const ApplicationContainer = styled.div`
421400
width: 100%;
422401
background-color: ${colors.gray[400]};
423-
display: block;
402+
display: flex;
403+
justify-content: center;
404+
align-items: center;
424405
padding: 24px 140px;
425406
box-sizing: border-box;
426-
max-height: 80vh;
427-
overflow-y: auto;
407+
min-height: 80vh;
428408
`;
429409

430-
const PdfViewport = styled.div`
410+
const PdfIframe = styled.iframe`
431411
width: 100%;
432-
max-width: 794px;
412+
height: 80vh;
413+
border: none;
433414
background-color: ${colors.extra.realWhite};
434-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
435-
display: flex;
436-
flex-direction: column;
437-
gap: 16px;
438-
padding: 20px 0;
439-
margin: 0 auto;
440-
canvas {
441-
max-width: 100%;
442-
height: auto !important;
443-
margin: 0 auto;
444-
display: block;
445-
}
415+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
446416
`;
447417

448418
const ApplicationLoadingContainer = styled(Skeleton)`

0 commit comments

Comments
 (0)