Skip to content

Commit 8f48bb3

Browse files
committed
fix(wasm-example): add error handling for login process and display error messages
1 parent 9d8d053 commit 8f48bb3

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

examples/sport-tracker-app/src/App.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const AppContent: React.FC = () => {
3636
const [refreshTrigger, setRefreshTrigger] = useState(0);
3737
const [sqliteSyncVersion, setSqliteSyncVersion] = useState<string>("");
3838
const [sqliteVersion, setSqliteVersion] = useState<string>("");
39+
const [loginError, setLoginError] = useState<string>("");
3940

4041
// Coach mode - true when logged in user is named "coach"
4142
const isCoachMode = (session: UserSession | null): boolean => {
@@ -392,6 +393,15 @@ const AppContent: React.FC = () => {
392393
);
393394
}
394395

396+
if (loginError) {
397+
return (
398+
<div className="error-container">
399+
<h2>Login Error</h2>
400+
<p>{loginError}</p>
401+
</div>
402+
);
403+
}
404+
395405
if (!isInitialized || loading) {
396406
return (
397407
<div className="loading-container">
@@ -425,6 +435,7 @@ const AppContent: React.FC = () => {
425435
onLogout={handleLogout}
426436
onUsersLoad={loadUsers}
427437
onRefresh={handleRefreshData}
438+
onError={setLoginError}
428439
/>
429440
<DatabaseStatus
430441
onCountsLoad={loadCounts}

examples/sport-tracker-app/src/SQLiteSync.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ export class SQLiteSync {
6060
throw new Error("Database not available");
6161
}
6262

63-
try {
64-
await this.db.sqliteSyncNetworkSync();
65-
} catch (e) {
66-
console.error("Error checking SQLite Sync changes:", e);
67-
}
63+
await this.db.sqliteSyncNetworkSync();
6864
}
6965

7066
/**

examples/sport-tracker-app/src/components/UserLogin.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface UserLoginProps {
1515
onLogout: () => Promise<void>;
1616
onUsersLoad: () => void;
1717
onRefresh: () => void;
18+
onError?: (error: string) => void; // Optional error handler
1819
}
1920

2021
const UserLogin: React.FC<UserLoginProps> = ({
@@ -24,6 +25,7 @@ const UserLogin: React.FC<UserLoginProps> = ({
2425
onLogout,
2526
onUsersLoad,
2627
onRefresh,
28+
onError
2729
}) => {
2830
const { db } = useDatabase();
2931
const [selectedUserId, setSelectedUserId] = useState<string>("");
@@ -113,6 +115,7 @@ const UserLogin: React.FC<UserLoginProps> = ({
113115
error
114116
);
115117
console.warn("SQLite Sync: Falling back to local refresh only");
118+
if(onError) onError("SQLite Sync - Failed to sync with SQLite Cloud: " + error);
116119
}
117120
} else {
118121
console.log(

examples/sport-tracker-app/src/db/database.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export class Database {
9797
return this.sendMessage("sqliteSyncSetToken", token);
9898
}
9999

100-
101100
async sqliteSyncNetworkSync(): Promise<void> {
102101
return this.sendMessage("sqliteSyncNetworkSync");
103102
}

0 commit comments

Comments
 (0)