@@ -4,34 +4,35 @@ const errors = require('./errors.js')
4
4
const { Response } = require ( 'minipass-fetch' )
5
5
const defaultOpts = require ( './default-opts.js' )
6
6
7
- const checkResponse = async ( { method, uri, res, registry, startTime, auth, opts } ) => {
8
- opts = { ...defaultOpts , ...opts }
9
- if ( res . headers . has ( 'npm-notice' ) && ! res . headers . has ( 'x-local-cache' ) )
10
- opts . log . notice ( '' , res . headers . get ( 'npm-notice' ) )
7
+ const checkResponse =
8
+ async ( { method, uri, res, registry, startTime, auth, opts } ) => {
9
+ opts = { ...defaultOpts , ...opts }
10
+ if ( res . headers . has ( 'npm-notice' ) && ! res . headers . has ( 'x-local-cache' ) )
11
+ opts . log . notice ( '' , res . headers . get ( 'npm-notice' ) )
11
12
12
- if ( res . status >= 400 ) {
13
- logRequest ( method , res , startTime , opts )
14
- if ( auth && auth . scopeAuthKey && ! auth . token && ! auth . auth ) {
13
+ if ( res . status >= 400 ) {
14
+ logRequest ( method , res , startTime , opts )
15
+ if ( auth && auth . scopeAuthKey && ! auth . token && ! auth . auth ) {
15
16
// we didn't have auth for THIS request, but we do have auth for
16
17
// requests to the registry indicated by the spec's scope value.
17
18
// Warn the user.
18
- opts . log . warn ( 'registry' , `No auth for URI, but auth present for scoped registry.
19
+ opts . log . warn ( 'registry' , `No auth for URI, but auth present for scoped registry.
19
20
20
21
URI: ${ uri }
21
22
Scoped Registry Key: ${ auth . scopeAuthKey }
22
23
23
24
More info here: https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry` )
25
+ }
26
+ return checkErrors ( method , res , startTime , opts )
27
+ } else {
28
+ res . body . on ( 'end' , ( ) => logRequest ( method , res , startTime , opts ) )
29
+ if ( opts . ignoreBody ) {
30
+ res . body . resume ( )
31
+ return new Response ( null , res )
32
+ }
33
+ return res
24
34
}
25
- return checkErrors ( method , res , startTime , opts )
26
- } else {
27
- res . body . on ( 'end' , ( ) => logRequest ( method , res , startTime , opts ) )
28
- if ( opts . ignoreBody ) {
29
- res . body . resume ( )
30
- return new Response ( null , res )
31
- }
32
- return res
33
35
}
34
- }
35
36
module . exports = checkResponse
36
37
37
38
function logRequest ( method , res , startTime , opts ) {
@@ -85,7 +86,8 @@ function checkErrors (method, res, startTime, opts) {
85
86
)
86
87
}
87
88
} else if ( res . status === 401 && body != null && / o n e - t i m e p a s s / . test ( body . toString ( 'utf8' ) ) ) {
88
- // Heuristic for malformed OTP responses that don't include the www-authenticate header.
89
+ // Heuristic for malformed OTP responses that don't include the
90
+ // www-authenticate header.
89
91
throw new errors . HttpErrorAuthOTP (
90
92
method , res , parsed , opts . spec
91
93
)
0 commit comments