Skip to content

Commit ceef3e0

Browse files
committed
feat: first use the third-party API for resolving usernames to UUID
The official API is just very unreliable it seems
1 parent 0780462 commit ceef3e0

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/minecraft/profile/MinecraftProfileService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,22 @@ export default class MinecraftProfileService {
132132
}
133133

134134
private async executeUsernameToUuidLookup(username: string): Promise<UsernameToUuidResponse | null> {
135-
let firstPartyApiFetchError: Error;
135+
let thirdPartyApiFetchError: Error;
136136

137137
try {
138-
return await this.minecraftApiClient.fetchUuidForUsername(username);
138+
return await this.thirdPartyMinecraftApiClient.fetchUuidForUsername(username);
139139
} catch (err: any) {
140140
if (!(err instanceof Error)) {
141141
throw err;
142142
}
143143

144-
firstPartyApiFetchError = err;
144+
thirdPartyApiFetchError = err;
145145
}
146146

147147
try {
148-
return await this.thirdPartyMinecraftApiClient.fetchUuidForUsername(username);
149-
} catch (thirdPartyApiFetchError: any) {
150-
throw new Error('Resolving Username to UUID failed', { cause: [firstPartyApiFetchError, thirdPartyApiFetchError] });
148+
return await this.minecraftApiClient.fetchUuidForUsername(username);
149+
} catch (firstPartyApiFetchError: any) {
150+
throw new Error('Resolving Username to UUID failed', { cause: [thirdPartyApiFetchError, firstPartyApiFetchError] });
151151
}
152152
}
153153
}

src/task_queue/tasks/ProxyPoolHttpClientHealthcheckTask.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export default class ProxyPoolHttpClientHealthcheckTask extends Task {
9090
};
9191
} catch (err: any) {
9292
SentrySdk.logAndCaptureWarning(`[ProxyHealthcheck] Proxy '${proxy.displayName}' is unhealthy: ${err.message}`, { err });
93+
if (err.message === 'SocksClient internal error (this should not happen)') {
94+
console.error(err);
95+
}
9396

9497
proxy.health = {
9598
unhealthy: true,

tests/unit/minecraft/profile/MinecraftProfileService.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe('#provideProfileByUsername', () => {
253253
expect(minecraftApiClient.fetchUuidForUsername).toHaveBeenCalledTimes(0);
254254
});
255255

256-
test('On Mojang API troubles (username->profile) the third-party API is used to determine the UUID', async () => {
256+
test('On API troubles (username->profile) the first-party API is used to determine the UUID', async () => {
257257
const expectedProfile = {
258258
profile: EXISTING_MC_PROFILE_RESPONSE,
259259
ageInSeconds: 0,
@@ -273,14 +273,14 @@ describe('#provideProfileByUsername', () => {
273273
expect(profileCache.findByUsername).toHaveBeenCalledTimes(1);
274274
expect(profileCache.findByUsername).toHaveBeenCalledWith(EXISTING_MC_NAME);
275275

276-
expect(minecraftApiClient.fetchUuidForUsername).toHaveBeenCalledTimes(1);
276+
expect(minecraftApiClient.fetchUuidForUsername).toHaveBeenCalledTimes(0);
277277
expect(minecraftApiClient.fetchProfileForUuid).toHaveBeenCalledTimes(1);
278278
expect(thirdPartyMinecraftApiClient.fetchUuidForUsername).toHaveBeenCalledTimes(1);
279279
});
280280

281-
test('On Mojang API troubles (username->profile) an error is thrown', async () => {
281+
test('On API troubles (username->profile) an error is thrown', async () => {
282282
profileCache.findByUsername.mockResolvedValue(null);
283-
minecraftApiClient.fetchUuidForUsername.mockImplementation(() => {
283+
thirdPartyMinecraftApiClient.fetchUuidForUsername.mockImplementation(() => {
284284
throw new Error('Connection timed out or something');
285285
});
286286

0 commit comments

Comments
 (0)