node/deps/npm/lib/utils/audit-error.js
Ruy Adorno f3d3769f9f
deps: upgrade npm to 7.6.1
PR-URL: https://github.com/nodejs/node/pull/37606
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2021-03-05 15:32:56 -05:00

36 lines
959 B
JavaScript

// print an error or just nothing if the audit report has an error
// this is called by the audit command, and by the reify-output util
// prints a JSON version of the error if it's --json
// returns 'true' if there was an error, false otherwise
const output = require('./output.js')
const auditError = (npm, report) => {
if (!report || !report.error)
return false
if (npm.command !== 'audit')
return true
const { error } = report
// ok, we care about it, then
npm.log.warn('audit', error.message)
const { body: errBody } = error
const body = Buffer.isBuffer(errBody) ? errBody.toString() : errBody
if (npm.flatOptions.json) {
output(JSON.stringify({
message: error.message,
method: error.method,
uri: error.uri,
headers: error.headers,
statusCode: error.statusCode,
body,
}, null, 2))
} else
output(body)
throw 'audit endpoint returned an error'
}
module.exports = auditError