From 46995c0bb25623dca1cbbfe61f2bc0403e1ac857 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 22 Jun 2022 13:51:49 +0200 Subject: [PATCH] Add gitignore and fixes --- .gitignore | 1 + main.js | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/main.js b/main.js index 56d34d4..111367c 100644 --- a/main.js +++ b/main.js @@ -134,13 +134,17 @@ async function main(){ const credentials = `Basic ` + Buffer.from(`${user}:${passw}`).toString('base64'); - let response = await fetch(urlOrganizations, { - method: "GET", - headers: { - Authorization: credentials - } - }); - + try { + var response = await fetch(urlOrganizations, { + method: "GET", + headers: { + Authorization: credentials + } + }); + } catch (notfound) { + console.error(`${error}Server '${config.grafanaUrl}' not found`.red); + process.exit(1); + }; let AllOrganizations = await response.json(); if (AllOrganizations.message==='invalid username or password') { @@ -262,6 +266,12 @@ async function main(){ console.log(colors.green.bold(`-------- Have been found ${numberOfObjects} results in ${totalDashboards} dashboards -------\n`)); + if (!response) { + console.log(`${error}The server don't exists`); + process.exit(1); + } + process.exit(); + } main(); \ No newline at end of file