Handle errors

This commit is contained in:
Natsumi
2024-10-07 20:09:30 +13:00
parent d16928f6de
commit d16d8399ca
2 changed files with 39 additions and 21 deletions

View File

@@ -69,22 +69,28 @@ namespace VRCX
{ {
if (hexString.Length != 32) if (hexString.Length != 32)
return 0; // it's cooked return 0; // it's cooked
var versionHexString = hexString.Substring(16, 8); // 16..24 try {
var variantVersionHexString = hexString.Substring(24, 8); // 24..32 var versionHexString = hexString.Substring(16, 8); // 16..24
var versionBytes = new byte[4]; var variantVersionHexString = hexString.Substring(24, 8); // 24..32
var variantVersionBytes = new byte[4]; var versionBytes = new byte[4];
for (var i = 0; i < 4; i++) var variantVersionBytes = new byte[4];
{ for (var i = 0; i < 4; i++)
var versionValue = Convert.ToInt32(versionHexString.Substring(i * 2, 2), 16); {
versionBytes[i] = (byte)versionValue; var versionValue = Convert.ToInt32(versionHexString.Substring(i * 2, 2), 16);
var variantVersionValue = Convert.ToInt32(variantVersionHexString.Substring(i * 2, 2), 16); versionBytes[i] = (byte)versionValue;
variantVersionBytes[i] = (byte)variantVersionValue; var variantVersionValue = Convert.ToInt32(variantVersionHexString.Substring(i * 2, 2), 16);
variantVersionBytes[i] = (byte)variantVersionValue;
}
var version = BitConverter.ToInt32(versionBytes, 0);
var variantVersion = BitConverter.ToInt32(variantVersionBytes, 0);
return version + variantVersion;
}
catch (Exception ex)
{
logger.Error($"Failed to convert hex to decimal: {hexString} {ex}");
return 0; // it's cooked
} }
var version = BitConverter.ToInt32(versionBytes, 0);
var variantVersion = BitConverter.ToInt32(variantVersionBytes, 0);
return version + variantVersion;
} }
public string GetVRChatCacheLocation() public string GetVRChatCacheLocation()

View File

@@ -2906,10 +2906,13 @@ speechSynthesis.getVoices();
try { try {
var args = await this.getFriends(params); var args = await this.getFriends(params);
friends = friends.concat(args.json); friends = friends.concat(args.json);
params.offset += 50;
break; break;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
if (err?.message?.includes('Not Found')) {
console.error('Awful workaround for awful VRC API bug');
break;
}
if (j === 9) { if (j === 9) {
throw err; throw err;
} }
@@ -2918,6 +2921,7 @@ speechSynthesis.getVoices();
}); });
} }
} }
params.offset += 50;
} }
return friends; return friends;
}; };
@@ -2944,10 +2948,13 @@ speechSynthesis.getVoices();
try { try {
var args = await this.getFriends(params); var args = await this.getFriends(params);
friends = friends.concat(args.json); friends = friends.concat(args.json);
params.offset += 50;
break; break;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
if (err?.message?.includes('Not Found')) {
console.error('Awful workaround for awful VRC API bug');
break;
}
if (j === 9) { if (j === 9) {
throw err; throw err;
} }
@@ -2955,6 +2962,7 @@ speechSynthesis.getVoices();
workerTimers.setTimeout(resolve, 5000); workerTimers.setTimeout(resolve, 5000);
}); });
} }
params.offset += 50;
} }
} }
return friends; return friends;
@@ -5444,9 +5452,11 @@ speechSynthesis.getVoices();
} }
try { try {
const params = new URLSearchParams(new URL(url).search); const params = new URLSearchParams(new URL(url).search);
let version = params.get('v'); const version = params.get('v');
if (version) return version; if (version) {
return '0' return version;
}
return '0';
} catch { } catch {
return '0'; return '0';
} }
@@ -9174,7 +9184,9 @@ speechSynthesis.getVoices();
console.error(err); console.error(err);
}); });
} }
await API.refreshFriends(); await API.refreshFriends().catch((err) => {
console.error(err);
});
API.reconnectWebSocket(); API.reconnectWebSocket();
}; };