blob: c7423c4472d5d7ba9802004db65d55e69d423b72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// 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
|