From 35485817a7159e2340d5b5f634550ceabe586f1a Mon Sep 17 00:00:00 2001 From: Sas Andy Date: Wed, 4 Dec 2024 10:22:35 +0700 Subject: [PATCH] revisi handle error --- config-etl-upload-national.json | 2 +- source/lib-etl.ts | 152 ++++++++++++++++++++++++++++++++ source/server.ts | 13 +-- 3 files changed, 160 insertions(+), 7 deletions(-) diff --git a/config-etl-upload-national.json b/config-etl-upload-national.json index b2a9b7c..0d7f0a0 100644 --- a/config-etl-upload-national.json +++ b/config-etl-upload-national.json @@ -1,5 +1,5 @@ { - "base_url": "http://riau/one-api/", + "base_url": "http:///one-api/", "schedule": ["0 5,12,17 * * *"], "delay": 5, "row_per_batch": 50 diff --git a/source/lib-etl.ts b/source/lib-etl.ts index f6e7233..2b50820 100644 --- a/source/lib-etl.ts +++ b/source/lib-etl.ts @@ -20,8 +20,16 @@ export const getBranch = async () => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -43,8 +51,16 @@ export const getMgmMcu = async () => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -69,8 +85,16 @@ export const uploadMgmMcu = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -92,8 +116,16 @@ export const getMgmHeader = async (mgmMcuID: string) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -116,8 +148,16 @@ export const getTop3Kelainan = async (mgmMcuID: string) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -139,8 +179,16 @@ export const getMcuorder = async (mgmMcuID: string) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -163,8 +211,16 @@ export const getAntropometri = async (mgmMcuID: string) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -187,8 +243,16 @@ export const getMcuSnapshotNote = async (mgmMcuID: string) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -210,8 +274,16 @@ export const getMgmMou = async () => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -236,8 +308,16 @@ export const uploadMgmHeader = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -260,8 +340,16 @@ export const getMgmDetail = async (mgmHeaderID: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -284,8 +372,16 @@ export const getMgmRiwayat = async (mgmHeaderID: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -336,8 +432,16 @@ export const uploadMgmRiwayat = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -362,8 +466,16 @@ export const uploadMgmMou = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -389,8 +501,16 @@ export const uploadTop3Kelainan = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -416,8 +536,16 @@ export const uploadMcuOrder = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -443,8 +571,16 @@ export const uploadAntropometri = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -470,8 +606,16 @@ export const uploadMcuSnapshotNote = async (branch: any, data: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; @@ -499,8 +643,16 @@ export const uploadMgmCompany = async (branchCode: any, mgmMcuID: any) => { } catch (e) { if (axios.isAxiosError(e)) { logging.error(NAME_SPACE, e.response?.data.toString()); + return { + status: "ERR", + message: e.response?.data.toString(), + }; } else if (e instanceof Error) { logging.error(NAME_SPACE, e.message); + return { + status: "ERR", + message: e.message, + }; } } }; diff --git a/source/server.ts b/source/server.ts index e393ae7..921c33e 100644 --- a/source/server.ts +++ b/source/server.ts @@ -58,6 +58,7 @@ async function Upload() { logging.info(NAME_SPACE, "Starting Job Upload national" + VERSION); logging.info(NAME_SPACE, "START GET BRANCH"); var respbranch = await getBranch(); + // console.log(respbranch); if (respbranch["status"] != "OK") { logging.error(NAME_SPACE, "\t Error", respbranch); } else { @@ -147,8 +148,8 @@ async function Upload() { } logging.info(NAME_SPACE, "\t END JOB GET MGM HEADER"); logging.info(NAME_SPACE, "\t ----------"); - // logging.info(NAME_SPACE, "\t wait 1s"); - // await delay(1000); + logging.info(NAME_SPACE, "\t wait 1s"); + await delay(1000); logging.info(NAME_SPACE, "\t START UPLOAD MGM HEADER"); for (let j = 0; j < mgmHeaderList.length; j++) { let headerNumber = j + 1; @@ -181,8 +182,8 @@ async function Upload() { ); logging.info(NAME_SPACE, "\t\t ----------"); - // logging.info(NAME_SPACE, "\t\t wait 1s"); - // await delay(600); + logging.info(NAME_SPACE, "\t\t wait 1s"); + await delay(500); //GET MGM DETAIL logging.info(NAME_SPACE, "\t\t\t START GET MGM DETAIL"); @@ -261,8 +262,8 @@ async function Upload() { ); logging.info(NAME_SPACE, "\t\t\t ----------"); - // logging.info(NAME_SPACE, "\t\t\t wait 1s"); - // await delay(1000); + logging.info(NAME_SPACE, "\t\t\t wait 1s"); + await delay(700); } } logging.info(NAME_SPACE, "\t END UPLOAD MGM HEADER");