diff --git a/app/(manage)/manage/games/games-client.tsx b/app/(manage)/manage/games/games-client.tsx index b39534f..4d7143e 100644 --- a/app/(manage)/manage/games/games-client.tsx +++ b/app/(manage)/manage/games/games-client.tsx @@ -125,7 +125,8 @@ export function GamesClient() { }) if (!res.ok) { - throw new Error(`Sync failed: HTTP ${res.status}`) + const errorData = await res.json().catch(() => null) + throw new Error(errorData?.error || `Sync failed: HTTP ${res.status}`) } const data = await res.json() @@ -133,15 +134,20 @@ export function GamesClient() { setSyncProgress((prev) => ({ ...prev, isRunning: false, - synced: data.synced, - failed: data.failed, + synced: data.synced || 0, + failed: data.failed || 0, currentGame: null, })) setSyncCompleted(true) setSelectedIds(new Set()) } catch (error) { console.error("Sync selected failed:", error) - alert("Sync failed. Check console for details.") + alert(`Sync failed: ${error instanceof Error ? error.message : String(error)}`) + setSyncProgress((prev) => ({ + ...prev, + isRunning: false, + currentGame: null, + })) } finally { setSyncing(false) } @@ -171,7 +177,8 @@ export function GamesClient() { }) if (!res.ok) { - throw new Error(`Sync failed: HTTP ${res.status}`) + const errorData = await res.json().catch(() => null) + throw new Error(errorData?.error || `Sync failed: HTTP ${res.status}`) } const data = await res.json() @@ -179,15 +186,20 @@ export function GamesClient() { setSyncProgress((prev) => ({ ...prev, isRunning: false, - total: data.total, - synced: data.synced, - failed: data.failed, + total: data.total || 0, + synced: data.synced || 0, + failed: data.failed || 0, currentGame: null, })) setSyncCompleted(true) } catch (error) { console.error("Sync all failed:", error) - alert("Sync failed. Check console for details.") + alert(`Sync failed: ${error instanceof Error ? error.message : String(error)}`) + setSyncProgress((prev) => ({ + ...prev, + isRunning: false, + currentGame: null, + })) } finally { setSyncing(false) } @@ -527,7 +539,10 @@ export function GamesClient() {

Syncing Games

- {syncProgress.current} of {syncProgress.total} games + {syncProgress.total > 0 + ? `${syncProgress.current} of ${syncProgress.total} games` + : "Preparing to sync..." + }

@@ -536,7 +551,7 @@ export function GamesClient() {
Progress - {Math.round((syncProgress.current / syncProgress.total) * 100)}% + {syncProgress.total > 0 ? Math.round((syncProgress.current / syncProgress.total) * 100) : 0}%