summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-fetch/check-response.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/npm-registry-fetch/check-response.js')
-rw-r--r--deps/npm/node_modules/npm-registry-fetch/check-response.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/deps/npm/node_modules/npm-registry-fetch/check-response.js b/deps/npm/node_modules/npm-registry-fetch/check-response.js
index 407a80e4ce..bfde699edc 100644
--- a/deps/npm/node_modules/npm-registry-fetch/check-response.js
+++ b/deps/npm/node_modules/npm-registry-fetch/check-response.js
@@ -8,7 +8,7 @@ module.exports = checkResponse
function checkResponse (method, res, registry, startTime, opts) {
opts = config(opts)
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) {
- opts.get('log').notice('', res.headers.get('npm-notice'))
+ opts.log.notice('', res.headers.get('npm-notice'))
}
checkWarnings(res, registry, opts)
if (res.status >= 400) {
@@ -16,6 +16,10 @@ function checkResponse (method, res, registry, startTime, opts) {
return checkErrors(method, res, startTime, opts)
} else {
res.body.on('end', () => logRequest(method, res, startTime, opts))
+ if (opts.ignoreBody) {
+ res.body.resume()
+ res.body = null
+ }
return res
}
}
@@ -25,7 +29,7 @@ function logRequest (method, res, startTime, opts) {
const attempt = res.headers.get('x-fetch-attempts')
const attemptStr = attempt && attempt > 1 ? ` attempt #${attempt}` : ''
const cacheStr = res.headers.get('x-local-cache') ? ' (from cache)' : ''
- opts.get('log').http(
+ opts.log.http(
'fetch',
`${method.toUpperCase()} ${res.status} ${res.url} ${elapsedTime}ms${attemptStr}${cacheStr}`
)
@@ -51,14 +55,14 @@ function checkWarnings (res, registry, opts) {
BAD_HOSTS.set(registry, true)
if (warnings['199']) {
if (warnings['199'].message.match(/ENOTFOUND/)) {
- opts.get('log').warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`)
+ opts.log.warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`)
} else {
- opts.get('log').warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`)
+ opts.log.warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`)
}
}
if (warnings['111']) {
// 111 Revalidation failed -- we're using stale data
- opts.get('log').warn(
+ opts.log.warn(
'registry',
`Using stale data from ${registry} due to a request error during revalidation.`
)
@@ -70,8 +74,9 @@ function checkErrors (method, res, startTime, opts) {
return res.buffer()
.catch(() => null)
.then(body => {
+ let parsed = body
try {
- body = JSON.parse(body.toString('utf8'))
+ parsed = JSON.parse(body.toString('utf8'))
} catch (e) {}
if (res.status === 401 && res.headers.get('www-authenticate')) {
const auth = res.headers.get('www-authenticate')
@@ -79,20 +84,25 @@ function checkErrors (method, res, startTime, opts) {
.map(s => s.toLowerCase())
if (auth.indexOf('ipaddress') !== -1) {
throw new errors.HttpErrorAuthIPAddress(
- method, res, body, opts.spec
+ method, res, parsed, opts.spec
)
} else if (auth.indexOf('otp') !== -1) {
throw new errors.HttpErrorAuthOTP(
- method, res, body, opts.spec
+ method, res, parsed, opts.spec
)
} else {
throw new errors.HttpErrorAuthUnknown(
- method, res, body, opts.spec
+ method, res, parsed, opts.spec
)
}
+ } else if (res.status === 401 && /one-time pass/.test(body.toString('utf8'))) {
+ // Heuristic for malformed OTP responses that don't include the www-authenticate header.
+ throw new errors.HttpErrorAuthOTP(
+ method, res, parsed, opts.spec
+ )
} else {
throw new errors.HttpErrorGeneral(
- method, res, body, opts.spec
+ method, res, parsed, opts.spec
)
}
})