From 2862fdc9fdac63d3699e761607b249ef867048ec Mon Sep 17 00:00:00 2001 From: swcho Date: Fri, 25 Jul 2025 00:50:03 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Gis.js=20fetch=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business_components/src/ui/map/Gis.js | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/common/business_components/src/ui/map/Gis.js b/packages/common/business_components/src/ui/map/Gis.js index fb0529828..90bd50fa4 100644 --- a/packages/common/business_components/src/ui/map/Gis.js +++ b/packages/common/business_components/src/ui/map/Gis.js @@ -20,28 +20,39 @@ import GisApp from './lib/gis.core'; export const GisContext = createContext({ gisCore: null, gisMap: null, treeData: null, checkedLayerIds: null }); export const useGisContext = () => useContext(GisContext); -export async function searchUpperPpls(fcltMngNo) { - const BASE_URL = process.env.NEXT_PUBLIC_SERVER_API_URL || ''; +export const searchUpperPpls = async (fcltMngNo) => { + const BASE_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || ''; const res = await fetch(`${BASE_URL}/v1/fcltmhl/upperPpls/${fcltMngNo}`, { method: "GET", }); + + let data = null; if (res.ok) { - const data = await res.json(); - return data; + try { + // 응답이 비어있는지 확인 + const contentLength = res.headers.get('content-length'); + if (contentLength === '0') alert(`해당 맨홀의 상류관로를 찾을 수 없습니다.`); + + // 응답 텍스트를 먼저 가져와서 빈 문자열인지 확인 + const text = await res.text(); + if (!text || text.trim() === '') alert(`해당 맨홀의 상류관로를 찾을 수 없습니다.`); + + // JSON 파싱 시도 + data = JSON.parse(text); + } catch (error) { + console.error('JSON parsing error:', error); + alert(`해당 맨홀의 상류관로를 찾을 수 없습니다.`); + } } - throw new Error('Failed to fetch data'); - console.log('상류관로 조회 결과:', res); const select = GisApp.Module.select; - if (!select || !Array.isArray(res)) return; const gisMap = GisApp.Module.core?.map; - if (!gisMap) return; let foundFeature = null; - res.forEach(item => { + data.forEach(item => { const pplMngNo = item.ppl_mng_no.trim(); gisMap.getLayers().getArray().filter(e => e.get("lyrTyNm") == 'tb_ms_swage_ppl').forEach(layer => { @@ -60,7 +71,6 @@ export async function searchUpperPpls(fcltMngNo) { if (foundFeature) select.selectMultiFeature(foundFeature, true); }); - console.log('찾은 피쳐:', foundFeature); if (!foundFeature) alert(`해당 맨홀의 상류관로를 찾을 수 없습니다.`); let geometry = foundFeature?.getGeometry(); @@ -75,7 +85,8 @@ export async function searchUpperPpls(fcltMngNo) { nearest: true, }); } -} +}; + function Gis({ isOpen,