fix: 하수관로 레이어 호출 api 수정

This commit is contained in:
swcho
2025-11-11 15:43:21 +09:00
parent fc89da8bef
commit a7ab57b5eb
+19 -2
View File
@@ -43,10 +43,27 @@ const Map = () => {
const fetchData = async () => {
try {
const data = await getData("v1/map/lyrStngs/SN_NETWORK");
let data;
const res = await fetch("/sewerage-service/api/v1/map/lyrStngs/SN_NETWORK", {
method: "GET",
});
if (res.ok) {
// 응답이 비어있는지 확인
const contentLength = res.headers.get('content-length');
if (contentLength === '0') data = null;
// 응답 텍스트를 먼저 가져와서 빈 문자열인지 확인
const text = await res.text();
if (!text || text.trim() === '') data = null;
// JSON 파싱 시도
data = JSON.parse(text);
}
setTreeData(data);
} catch (error) {
console.error("데이터 불러오기 실패:", error);
console.error('JSON parsing error:', error);
// JSON 파싱에 실패한 경우, 원본 텍스트 또는 null 반환
throw new Error('Invalid JSON response from server');
}
};