Skip to content

Commit 594de15

Browse files
committed
Fix recursion and exception in token refresh
1 parent e400b26 commit 594de15

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

services/tdei.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,29 @@ export class TdeiClient extends BaseHttpClient implements ICancelableClient {
169169
}
170170

171171
async refreshToken() {
172-
const response = await super._post('refresh-token', this.#auth.refreshToken);
173-
174-
if (response.status === 401) {
175-
this.#auth.clear();
172+
try {
173+
const response = await super._send('refresh-token', 'POST', this.#auth.refreshToken);
174+
this.#setAuth(this.#auth.username, await response.json());
175+
} catch (e: unknown) {
176+
if (e instanceof BaseHttpClientError && e.response.status === 401) {
177+
this.#auth.clear();
178+
}
176179
}
177-
178-
this.#setAuth(this.#auth.username, await response.json());
179180
}
180181

181182
async tryRefreshAuth() {
182-
if (this.#auth.needsRefresh) {
183+
if (!this.#auth.needsRefresh) {
184+
return false;
185+
}
186+
187+
try {
183188
await this.refreshToken();
184-
return true
189+
} catch(e: unknown) {
190+
console.warn('Exception when refreshing TDEI access token', e);
191+
return false;
185192
}
186193

187-
return false
194+
return true;
188195
}
189196

190197
restartAutoAuthRefresh() {

0 commit comments

Comments
 (0)