Skip to content

Commit

Permalink
polish: do not log the error object when refreshing a token fails (#851)
Browse files Browse the repository at this point in the history
We handle the error anyway (by doing a fresh login) which has its own logging and messaging. In the future we should add a DEBUG mode that logs all requests/errors/warnings, but that's for later.
  • Loading branch information
threepointone committed Apr 26, 2022
1 parent 331c659 commit 277b254
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/early-timers-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

polish: do not log the error object when refreshing a token fails

We handle the error anyway (by doing a fresh login) which has its own logging and messaging. In the future we should add a DEBUG mode that logs all requests/errors/warnings, but that's for later.
9 changes: 5 additions & 4 deletions packages/wrangler/src/__tests__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("User", () => {
});

// TODO: Improve OAuth mocking to handle `/token` endpoints from different calls
it("should report error message for failed token refresh", async () => {
it("should handle errors for failed token refresh", async () => {
mockOAuthServerCallback();
writeAuthConfigFile({
oauth_token: "hunter2",
Expand All @@ -100,9 +100,10 @@ describe("User", () => {
});

// Handles the requireAuth error throw from failed login that is unhandled due to directly calling it here
await expect(requireAuth({} as Config, false)).rejects.toThrowError();
expect(std.err).toContain(
`Error: <html> <body> This shouldn't be sent, but should be handled </body> </html>`
await expect(
requireAuth({} as Config, false)
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Did not login, quitting..."`
);
});

Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ async function refreshToken(): Promise<boolean> {
writeAuthConfigFile({ oauth_token, expiration_time, refresh_token });
return true;
} catch (err) {
console.error(err);
return false;
}
}
Expand Down

0 comments on commit 277b254

Please sign in to comment.