Skip to content

Commit

Permalink
Add error handler for fetchCoreIndex and call end()
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 1, 2024
1 parent d9d0c08 commit 46db233
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions is-vulnerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function fetchCoreIndex () {
await new Promise((resolve) => {
request(CORE_RAW_URL, (res) => {
if (res.statusCode !== 200) {
console.error('Request to Github failed. Aborting...')
console.error(`Request to Github returned http status ${res.statusCode}. Aborting...`)
process.nextTick(() => { process.exit(1) })
}

Expand All @@ -46,10 +46,13 @@ async function fetchCoreIndex () {
})

fileStream.on('error', (err) => {
console.error(`Error while writing to file '${coreLocalFile}'`, err.message)
console.error(`Error ${err.message} while writing to '${coreLocalFile}'. Aborting...`)
process.nextTick(() => { process.exit(1) })
})
})
}).on('error', (err) => {
console.error(`Request to Github returned error ${err.message}. Aborting...`)
process.nextTick(() => { process.exit(1) })
}).end()
})
return readLocal(coreLocalFile)
}
Expand All @@ -58,7 +61,7 @@ async function getCoreIndex () {
return new Promise((resolve) => {
const req = request(CORE_RAW_URL, { method: 'HEAD' }, (res) => {
if (res.statusCode !== 200) {
console.error('Request to Github failed. Aborting...')
console.error(`Request to Github returned http status ${res.statusCode}. Aborting...`)
process.nextTick(() => { process.exit(1) })
}

Expand All @@ -75,8 +78,8 @@ async function getCoreIndex () {
}
})

req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`)
req.on('error', (err) => {
console.error(`Request to Github returned error ${err.message}. Aborting...`)
process.nextTick(() => { process.exit(1) })
})

Expand Down

0 comments on commit 46db233

Please sign in to comment.