(npm, report)
| 6 | // Returns 'true' if there was an error, false otherwise. |
| 7 | |
| 8 | const auditError = (npm, report) => { |
| 9 | if (!report?.error) { |
| 10 | return false |
| 11 | } |
| 12 | |
| 13 | if (npm.command !== 'audit') { |
| 14 | return true |
| 15 | } |
| 16 | |
| 17 | const { error } = report |
| 18 | |
| 19 | // ok, we care about it, then |
| 20 | log.warn('audit', error.message) |
| 21 | const { body: errBody } = error |
| 22 | const body = Buffer.isBuffer(errBody) ? errBody.toString() : errBody |
| 23 | if (npm.flatOptions.json) { |
| 24 | output.buffer({ |
| 25 | message: error.message, |
| 26 | method: error.method, |
| 27 | uri: replaceInfo(error.uri), |
| 28 | headers: error.headers, |
| 29 | statusCode: error.statusCode, |
| 30 | body, |
| 31 | }) |
| 32 | } else { |
| 33 | output.standard(body) |
| 34 | } |
| 35 | |
| 36 | // XXX we should throw a real error here |
| 37 | throw 'audit endpoint returned an error' |
| 38 | } |
| 39 | |
| 40 | module.exports = auditError |
no test coverage detected
searching dependent graphs…