Welcome to mirror list, hosted at ThFree Co, Russian Federation.

audit-error.js « utils « lib - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4ab26fd0c6979676d50a61c707688cd38ee8326 (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
37
// 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 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) {
    npm.output(JSON.stringify({
      message: error.message,
      method: error.method,
      uri: error.uri,
      headers: error.headers,
      statusCode: error.statusCode,
      body,
    }, null, 2))
  } else {
    npm.output(body)
  }

  throw 'audit endpoint returned an error'
}

module.exports = auditError