diff --git a/src/auth/index.ts b/src/auth/index.ts index eb893958..1f1e4fba 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -37,6 +37,8 @@ export class Authenticator { }); try { + this.accessToken = undefined; + const { access_token } = await httpClient .request<{ access_token: string; @@ -44,6 +46,9 @@ export class Authenticator { .ready(); this.accessToken = access_token; } catch (error) { + console.log("Failed to refresh access token"); + console.error(error); + console.log("Performing login..."); await this.authenticate(); } } @@ -61,6 +66,8 @@ export class Authenticator { password }); + this.accessToken = undefined; + const { access_token, refresh_token } = await httpClient .request("POST", url, { body, diff --git a/src/http/node.ts b/src/http/node.ts index 151f10b0..2cf0ff06 100644 --- a/src/http/node.ts +++ b/src/http/node.ts @@ -52,14 +52,13 @@ export class NodeHttpClient { const withProtocol = assignProtocol(url); + const userAgent = headers["user-agent"] || DEFAULT_USER_AGENT; const response = await fetch(withProtocol, { agent, signal: controller.signal as AbortSignal, method, headers: { - "user-agent": headers["user-agent"] - ? headers["user-agent"] - : DEFAULT_USER_AGENT, + "user-agent": userAgent, "Content-Type": "application/json", ...headers }, @@ -70,6 +69,7 @@ export class NodeHttpClient { try { await this.authenticator.refreshAccessToken(); } catch (error) { + console.error(error); throw new AuthenticationError({ message: "Failed to refresh access token" });