diff --git a/src/analysis.js b/src/analysis.js index c7fb3e4..d8c4f5b 100644 --- a/src/analysis.js +++ b/src/analysis.js @@ -34,26 +34,29 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) { body: provided.content }) let result - if(!html) { - result = await resp.json() - } - else { - result = await resp.text() - } - if (process.env["EXHORT_DEBUG"] === "true") { - let exRequestId = resp.headers.get("ex-request-id"); - if(exRequestId) - { - console.log("Unique Identifier associated with this request - ex-request-id=" + exRequestId) + if(resp.status === 200) { + if (!html) { + result = await resp.json() + } else { + result = await resp.text() } - EndTime = new Date() - console.log("Response body received from exhort server : " + EOL + EOL) - console.log(console.log(JSON.stringify(result,null , 4))) - console.log("Ending time of sending stack analysis request to exhort server= " + EndTime) - let time = (EndTime - startTime) / 1000 - console.log("Total Time in seconds: " + time) + if (process.env["EXHORT_DEBUG"] === "true") { + let exRequestId = resp.headers.get("ex-request-id"); + if (exRequestId) { + console.log("Unique Identifier associated with this request - ex-request-id=" + exRequestId) + } + EndTime = new Date() + console.log("Response body received from exhort server : " + EOL + EOL) + console.log(console.log(JSON.stringify(result, null, 4))) + console.log("Ending time of sending stack analysis request to exhort server= " + EndTime) + let time = (EndTime - startTime) / 1000 + console.log("Total Time in seconds: " + time) + } + } else { + throw new Error(`Got error response from exhort backend - http return code : ${resp.status}, error message => ${await resp.text()}`) } + return Promise.resolve(result) } @@ -80,18 +83,22 @@ async function requestComponent(provider, data, url, opts = {}, path = '') { }, body: provided.content }) - let result = await resp.json() - if (process.env["EXHORT_DEBUG"] === "true") { - let exRequestId = resp.headers.get("ex-request-id"); - if(exRequestId) - { - console.log("Unique Identifier associated with this request - ex-request-id=" + exRequestId) - } - console.log("Response body received from exhort server : " + EOL + EOL) - console.log(JSON.stringify(result,null , 4)) - console.log("Ending time of sending component analysis request to exhort server= " + new Date()) + let result + if(resp.status === 200) { + result = await resp.json() + if (process.env["EXHORT_DEBUG"] === "true") { + let exRequestId = resp.headers.get("ex-request-id"); + if (exRequestId) { + console.log("Unique Identifier associated with this request - ex-request-id=" + exRequestId) + } + console.log("Response body received from exhort server : " + EOL + EOL) + console.log(JSON.stringify(result, null, 4)) + console.log("Ending time of sending component analysis request to exhort server= " + new Date()) + } + } else { + throw new Error(`Got error response from exhort backend - http return code : ${resp.status}, error message => ${await resp.text()}`) } return Promise.resolve(result)