chore: log RetroAchievements sync decisions and guard session-end errors

Add info logging at each RA sync gate (missing credentials, no game mapping, fetch result with new unlock count) and catch errors from the session-end sync so a failed RA fetch no longer rejects unhandled.
This commit is contained in:
Moyasee
2026-06-30 23:27:52 +03:00
parent 82776fd58a
commit c021fb75ed
2 changed files with 25 additions and 3 deletions
@@ -171,9 +171,11 @@ const finalizeEmulatorSession = async (gameKey: string): Promise<void> => {
});
if (game.shop === "launchbox") {
void syncRetroAchievements({
syncRetroAchievements({
objectId: game.objectId,
shop: game.shop,
}).catch((error) => {
logger.error("Failed to sync RetroAchievements on session end", error);
});
}
};
@@ -57,7 +57,13 @@ export const syncRetroAchievements = async ({
const webApiKey = userPreferences?.retroAchievementsWebApiKey;
const username = userPreferences?.retroAchievementsUsername;
if (!webApiKey || !username) return null;
if (!webApiKey || !username) {
logger.info("RetroAchievements sync skipped: missing credentials", {
hasWebApiKey: Boolean(webApiKey),
hasUsername: Boolean(username),
});
return null;
}
const gameId = await resolveRetroAchievementsGameId(
objectId,
@@ -65,7 +71,13 @@ export const syncRetroAchievements = async ({
retroAchievementsGameId
);
if (!gameId) return null;
if (!gameId) {
logger.info("RetroAchievements sync skipped: no game mapping", {
objectId,
shop,
});
return null;
}
const data = await RetroAchievementsClient.getGameInfoAndUserProgress({
username,
@@ -124,6 +136,14 @@ export const syncRetroAchievements = async ({
language: cachedAchievements?.language,
});
logger.info("RetroAchievements progress fetched", {
objectId,
shop,
gameId,
remoteCount: remoteAchievements.length,
newUnlockCount,
});
if (newUnlockCount > 0) {
HydraApi.post(
`/profile/games/${shop}/${objectId}/retroachievements/sync`,