fix(cupang): itemcode 조회 오류를 로그+API+화면에 노출 (원인 진단)

- ItemcodeReader.last_error 추가, _run 실패 시 logger.exception + 메시지 보존
- /api/products/all 응답에 error/count 추가
- products 화면: 결과 0 일 때 조회오류/사유 표시 (그냥 '결과 없음' 대신)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-05-30 21:16:54 +09:00
parent 8f3761aeae
commit cb43fe1257
3 changed files with 20 additions and 3 deletions
+8 -1
View File
@@ -28,10 +28,13 @@ product_name_snapshot 만 보존한다.
from __future__ import annotations
import logging
import os
import re
from typing import Any
logger = logging.getLogger("cupang.itemcode")
# 안전한 SQL 식별자(테이블/컬럼)만 허용 — 인젝션 방지.
_IDENT_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_.]*$")
@@ -55,6 +58,7 @@ class ItemcodeReader:
self._sql: str | None = None
self.enabled = False
self.reason = ""
self.last_error = "" # 마지막 조회 오류(진단용, 비밀값 없음)
self._configure()
def _configure(self) -> None:
@@ -130,7 +134,10 @@ class ItemcodeReader:
rows = conn.execute(
self._sql, {"q": like, "limit": int(limit)}
).fetchall()
except Exception: # noqa: BLE001 — 비밀값 노출 없이 빈 결과. 상세는 서버 로그.
self.last_error = ""
except Exception as exc: # noqa: BLE001 — 모듈을 죽이지 않음. 원인은 로그 + last_error.
self.last_error = f"{type(exc).__name__}: {exc}"
logger.exception("itemcode 조회 실패 (SQL/스키마 확인 필요)")
return []
out: list[dict[str, Any]] = []
for r in rows: