Skip to content

Commit

Permalink
chore: Broaden verbage of error to include generic no-access possibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Jul 19, 2022
1 parent c02f027 commit 29c8119
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions commands/publish/__tests__/get-npm-username.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ describe("getNpmUsername", () => {
expect(console.error).toHaveBeenCalledWith("third-party whoami fail");
});

test("logs failure message when npm automation token is suspected", async () => {
test("logs failure message when npm returns forbidden response", async () => {
fetch.json.mockImplementationOnce(() => {
const err = new Error("npm profile fail due to automation token's insufficient permissions");
const err = new Error("npm profile fail due to insufficient permissions");

err.code = "E403";

Expand All @@ -80,11 +80,9 @@ describe("getNpmUsername", () => {
const opts = { registry: "https://registry.npmjs.org/" };

await expect(getNpmUsername(opts)).rejects.toThrow(
"Cannot verify access when authenticating with a npm automation token. Set `command.publish.verifyAccess=false` in your lerna.json to skip this verification, or use a different type of npm access token (https://docs.npmjs.com/creating-and-viewing-access-tokens)."
);
expect(console.error).toHaveBeenCalledWith(
"npm profile fail due to automation token's insufficient permissions"
"Access verification failed. If you are authenticating with a npm automation token, set `command.publish.verifyAccess=false` in your lerna.json to skip this verification, or use a different type of npm access token (https://docs.npmjs.com/creating-and-viewing-access-tokens)."
);
expect(console.error).toHaveBeenCalledWith("npm profile fail due to insufficient permissions");
});

test("allows third-party registries to fail with a stern warning", async () => {
Expand Down
2 changes: 1 addition & 1 deletion commands/publish/lib/get-npm-username.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getNpmUsername(options) {
if (err.code === "E403") {
throw new ValidationError(
"ENEEDAUTH",
"Cannot verify access when authenticating with a npm automation token. Set `command.publish.verifyAccess=false` in your lerna.json to skip this verification, or use a different type of npm access token (https://docs.npmjs.com/creating-and-viewing-access-tokens)."
"Access verification failed. If you are authenticating with a npm automation token, set `command.publish.verifyAccess=false` in your lerna.json to skip this verification, or use a different type of npm access token (https://docs.npmjs.com/creating-and-viewing-access-tokens)."
);
}

Expand Down

0 comments on commit 29c8119

Please sign in to comment.