Skip to content

Commit

Permalink
Feat: 없는 지하철역 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
sw0501 committed Dec 6, 2023
1 parent e9fe077 commit ffd05f3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions BackendTS/routes/subwaydata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getSubwayStationName(stNm:string, callback:(nameList:Array<SubwayStatio
}
}

function getSubwayStationInfo(stCd:string, stNm:string, callback:(stationInfo:SubwayStationInfo)=>void) {
function getSubwayStationInfo(stCd:string, stNm:string, callback:(stationInfo:SubwayStationInfo|null)=>void) {
try {

const connection:mysql.connection = db.return_connection();
Expand All @@ -57,12 +57,10 @@ function getSubwayStationInfo(stCd:string, stNm:string, callback:(stationInfo:Su
console.log(err);
}

/*
//NULL error
if (results.length !== 0) {
return callback();
if (results.length === 0) {
return callback(null);
}
*/

const url:string = 'https://openapi.kric.go.kr/openapi/convenientInfo/stationInfo';
let queryParams:string = '?' + encodeURI('serviceKey');
Expand Down Expand Up @@ -544,9 +542,17 @@ router.get('/stationInfo/:stCd/:stNm', async (req:Request, res:Response) => {
const stNm = req.params.stNm;

await getSubwayStationInfo(stCd, stNm, stationinfo => {
return res.status(200).json({
stationinfo
})
if(stationinfo === null){
return res.status(500).json({
error: "No Station"
})
}

else{
return res.status(200).json({
stationinfo
})
}
})
}
catch (e) {
Expand Down Expand Up @@ -673,7 +679,7 @@ router.get('/transferMove/transferList/:stCd/:stNm/:railCd/:lnCd', async (req:Re
await getTransferList(stCd, stNm, railCd, lnCd, transferInfo => {
if (transferInfo.sourceStation.length === 0 || transferInfo.transferStation.length === 0) {
return res.status(500).json({
error: 404,
error: 500,
errorString: "Not Transfer Station"
})
}
Expand Down

0 comments on commit ffd05f3

Please sign in to comment.