No longer crash if unable to login to VRChat

This commit is contained in:
2023-04-23 15:40:44 +07:00
parent 7731fbdd64
commit 874a65888d
3 changed files with 17 additions and 8 deletions
+16 -1
View File
@@ -29,6 +29,7 @@ interface Cache {
class VRChatAPI {
public client: VRChatAPIs | null;
public configuration: VRChat.Configuration | null;
private ready = false;
private cache: Cache;
private useragent: string | null = null;
@@ -66,8 +67,18 @@ class VRChatAPI {
};
Logger.info('Logging in to VRChat');
let res = await this.client.AuthenticationApi.getCurrentUser();
let res;
try {
res = await this.client.AuthenticationApi.getCurrentUser();
} catch (err: any) {
if (err.response?.status === 401) {
Logger.error('Unable to log in to VRChat, check your credentials');
return;
} else throw err;
}
this.ready = true;
Logger.info('Logged in to VRChat as ' + res.data.displayName);
setInterval(() => {
@@ -86,6 +97,10 @@ class VRChatAPI {
}, VRC_CACHE_DURATION);
}
public isReady(): boolean {
return this.ready;
}
public async getCachedUserById(id: string) {
if (typeof this.cache.Users[id] !== 'undefined') {
Logger.debug('[VRChat] [Cache] Cache hit for user ' + id);