mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 23:25:21 +00:00

Refs: https://github.com/npm/cli/blob/latest/CHANGELOG.md#702-2020-10-16 PR-URL: https://github.com/nodejs/node/pull/35667 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
40 lines
1004 B
JavaScript
40 lines
1004 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 npm = require('../npm.js')
|
|
const auditError = (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
|