Refactor token refresh logic to streamline error handling.
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
This commit is contained in:
@ -130,24 +130,20 @@ export class AuthV2Repo {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.requestWithToken(this.refreshToken!, "/auth", {
|
const response = await this.requestWithToken(this.refreshToken!, "/auth", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
}).then(value => {
|
}).then(value => {
|
||||||
if (value.status === 401) {
|
if (value.status === 401) {
|
||||||
throw new Error("Unauthorized");
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}).then(value => value.json())
|
|
||||||
.then(value => AuthTokenSchema.parse(value));
|
|
||||||
|
|
||||||
this.setLoginState(response);
|
|
||||||
} catch (e) {
|
|
||||||
this.resetRefreshToken();
|
this.resetRefreshToken();
|
||||||
this.resetAccessToken();
|
this.resetAccessToken();
|
||||||
return;
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return value.json();
|
||||||
|
}).then(value => AuthTokenSchema.parse(value));
|
||||||
|
|
||||||
|
this.setLoginState(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
async request(url: string, params: RequestInit = {}) {
|
async request(url: string, params: RequestInit = {}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user