From 891b7aedde1713e2be378832006a9a50a77330e6 Mon Sep 17 00:00:00 2001 From: chaeeun-Han Date: Fri, 21 Apr 2023 17:09:45 +0900 Subject: [PATCH] MDS-128 !HOTFIX: Add undefined error handler --- backend/util/OpenAPI.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/util/OpenAPI.js b/backend/util/OpenAPI.js index 93f219b..f64846d 100644 --- a/backend/util/OpenAPI.js +++ b/backend/util/OpenAPI.js @@ -30,7 +30,11 @@ function insertGrain(url, queryParams) { async function (error, response, body) { var data; // 에러는 xml 또는 json으로 오고 statusCode로는 잡을 수 없음 - if (body[0] == '<') { + if (body == undefined) { + console.log(body); + return reject(); + } + else if (body[0] == '<') { console.log(body); return reject(); } @@ -86,7 +90,11 @@ function insertPermission(url, queryParams) { function (error, response, body) { var data; // 에러는 xml 또는 json으로 오고 statusCode로는 잡을 수 없음 - if (body[0] == '<') { + if (body == undefined) { + console.log(body); + return reject(); + } + else if (body[0] == '<') { console.log(body); return reject(); } @@ -100,7 +108,7 @@ function insertPermission(url, queryParams) { // 정상 response for (var i = 0; i < data.length; ++i) { - (async() => { + (async () => { await prisma.permission.create({ data: { itemSeq: data[i].ITEM_SEQ, @@ -154,7 +162,11 @@ function insertHousehold(url, queryParams) { async function (error, response, body) { var data; // 에러는 xml 또는 json으로 오고 statusCode로는 잡을 수 없음 - if (body[0] == '<') { + if (body == undefined) { + console.log(body); + return reject(); + } + else if (body[0] == '<') { console.log(body); return reject(); } @@ -202,7 +214,7 @@ function grainDB() { for (var pageNo = 1; pageNo <= loopCount; ++pageNo) { var queryParams = "?" + encodeURIComponent("serviceKey") + "=" + process.env.SERVICE_KEY; - queryParams += "&" + encodeURIComponent("numOfRows") + "=" + encodeURIComponent(pageNo == loopCount? endRows: numOfRows); + queryParams += "&" + encodeURIComponent("numOfRows") + "=" + encodeURIComponent(pageNo == loopCount ? endRows : numOfRows); queryParams += "&" + encodeURIComponent("pageNo") + "=" + encodeURIComponent(pageNo); queryParams += "&" + encodeURIComponent("type") + "=" + encodeURIComponent("json"); @@ -241,10 +253,10 @@ function permissionDB() { for (var pageNo = 1; pageNo <= loopCount; ++pageNo) { var queryParams = "?" + encodeURIComponent("serviceKey") + "=" + process.env.SERVICE_KEY; - queryParams += "&" + encodeURIComponent("numOfRows") + "=" + encodeURIComponent(pageNo == loopCount? endRows: numOfRows); + queryParams += "&" + encodeURIComponent("numOfRows") + "=" + encodeURIComponent(pageNo == loopCount ? endRows : numOfRows); queryParams += "&" + encodeURIComponent("pageNo") + "=" + encodeURIComponent(pageNo); queryParams += "&" + encodeURIComponent("type") + "=" + encodeURIComponent("json"); - + await insertPermission(url, queryParams).then(() => { process.stdout.clearLine(); process.stdout.cursorTo(0); @@ -280,7 +292,7 @@ function householdDB() { for (var pageNo = 1; pageNo <= loopCount; ++pageNo) { var queryParams = "?" + encodeURIComponent("serviceKey") + "=" + process.env.SERVICE_KEY; - queryParams += "&" + encodeURIComponent("numOfRows") + "=" + encodeURIComponent(pageNo == loopCount? endRows: numOfRows); + queryParams += "&" + encodeURIComponent("numOfRows") + "=" + encodeURIComponent(pageNo == loopCount ? endRows : numOfRows); queryParams += "&" + encodeURIComponent("pageNo") + "=" + encodeURIComponent(pageNo); queryParams += "&" + encodeURIComponent("type") + "=" + encodeURIComponent("json");