Skip to content

Commit 5b2ac04

Browse files
committed
Adds support for npm-notice during OTP requests
1 parent 751c895 commit 5b2ac04

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/errors.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ export class ResponseError extends Error {
3434
responseCode: number;
3535
}
3636

37-
export class OneTimePasswordError extends Error {}
37+
export class OneTimePasswordError extends Error {
38+
constructor(notice: string) {
39+
super();
40+
this.notice = notice;
41+
}
42+
43+
notice: string;
44+
}

src/registries/npm-registry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export default class NpmRegistry extends Registry {
191191
}
192192

193193
this.reporter.info(this.reporter.lang('twoFactorAuthenticationEnabled'));
194+
if (error.notice) {
195+
this.reporter.info(error.notice);
196+
}
197+
194198
this.otp = await getOneTimePassword(this.reporter);
195199

196200
this.requestManager.clearCache();

src/util/request-manager.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,8 @@ export default class RequestManager {
440440

441441
if (res.statusCode === 401 && res.headers['www-authenticate']) {
442442
const authMethods = res.headers['www-authenticate'].split(/,\s*/).map(s => s.toLowerCase());
443-
444443
if (authMethods.indexOf('otp') !== -1) {
445-
reject(new OneTimePasswordError());
444+
reject(new OneTimePasswordError(res.headers['npm-notice']));
446445
return;
447446
}
448447
}

0 commit comments

Comments
 (0)