Skip to content

Commit

Permalink
Merge pull request #128 from zvigrinberg/hotfix/expose-exhort-errors
Browse files Browse the repository at this point in the history
fix: expose exhort backend errors to clients
  • Loading branch information
zvigrinberg authored Apr 11, 2024
2 parents c3251e1 + f0c8ea5 commit e7c4f42
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions src/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down

0 comments on commit e7c4f42

Please sign in to comment.