Skip to content

Commit 9ba0919

Browse files
committed
add try-catch block around projectsusers insert
1 parent 846e156 commit 9ba0919

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/sync.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ async function syncUsers(fast42Api: Fast42, lastPullDate: Date | undefined): Pro
173173
log(2, `Processing page ${pageIndex} with ${usersData.length} users...`);
174174
const dbUsers = usersData.map((user: any) => transformApiUserToDb(user, campusId));
175175
await DatabaseService.insertManyUsers(dbUsers);
176+
// No try-catch block here, needs to fail if users fail to sync, otherwise projectsusers cannot be connected to user ids
176177
}
177178
pageIndex = 0;
178179
hasMorePages = true;
@@ -233,8 +234,13 @@ async function syncProjectUsers(fast42Api: Fast42, lastPullDate: Date | undefine
233234
}
234235

235236
log(2, `Processing page ${pageIndex} with ${projectUsersData.length} projectUsers...`);
236-
const dbProjectUsers = projectUsersData.map(transformApiProjectUserToDb);
237-
await DatabaseService.insertManyProjectUsers(dbProjectUsers);
237+
try {
238+
const dbProjectUsers = projectUsersData.map(transformApiProjectUserToDb);
239+
await DatabaseService.insertManyProjectUsers(dbProjectUsers);
240+
} catch (error) {
241+
console.error(`Failed to insert project users for project ${projectId} on page ${pageIndex}:`, error);
242+
// Continue syncing other project users even if insertion fails, can always repopulate the database
243+
}
238244
}
239245
pageIndex = 0;
240246
hasMorePages = true;

0 commit comments

Comments
 (0)