Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

importStatusManager.ts error handling

Edward Cui2431f239c63c
diff --git a/server/src/services/import/importStatusManager.ts b/server/src/services/import/importStatusManager.ts
index a9663ac8e..154c4e633 100644
--- a/server/src/services/import/importStatusManager.ts
+++ b/server/src/services/import/importStatusManager.ts
@@ -8,7 +8,12 @@ type InsertImportStatus = typeof importStatus.$inferInsert;
export class ImportStatusManager {
static async createImportStatus(data: InsertImportStatus): Promise<void> {
- await db.insert(importStatus).values(data);
+ try {
+ await db.insert(importStatus).values(data);
+ } catch (error) {
+ console.error("Failed to create import status:", error);
+ throw new Error(`Failed to create import status: ${error instanceof Error ? error.message : "Unknown error"}`);
+ }
}
static async updateStatus(
@@ -18,29 +23,44 @@ export class ImportStatusManager {
): Promise<void> {
const completedAt = status === "completed" || status === "failed" ? DateTime.utc().toISO() : null;
- await db
- .update(importStatus)
- .set({ status, errorMessage, completedAt })
- .where(eq(importStatus.importId, importId));
+ try {
+ await db
+ .update(importStatus)
+ .set({ status, errorMessage, completedAt })
+ .where(eq(importStatus.importId, importId));
+ } catch (error) {
+ console.error(`Failed to update import status for ${importId}:`, error);
+ throw new Error(`Failed to update import status: ${error instanceof Error ? error.message : "Unknown error"}`);
+ }
}
static async updateProgress(
importId: string,
importedEvents: number,
): Promise<void> {
- await db
- .update(importStatus)
- .set({
- importedEvents: sql`${importStatus.importedEvents} + ${importedEvents}`,
- })
- .where(eq(importStatus.importId, importId));
+ try {
+ await db
+ .update(importStatus)
+ .set({
+ importedEvents: sql`${importStatus.importedEvents} + ${importedEvents}`,
+ })
+ .where(eq(importStatus.importId, importId));
+ } catch (error) {
+ console.error(`Failed to update import progress for ${importId}:`, error);
+ throw new Error(`Failed to update import progress: ${error instanceof Error ? error.message : "Unknown error"}`);
+ }
}
static async getImportsForSite(siteId: number, limit = 10): Promise<SelectImportStatus[]> {
- return db.query.importStatus.findMany({
- where: eq(importStatus.siteId, siteId),
- orderBy: [desc(importStatus.startedAt)],
- limit,
- });
+ try {
+ return await db.query.importStatus.findMany({
+ where: eq(importStatus.siteId, siteId),
+ orderBy: [desc(importStatus.startedAt)],
+ limit,
+ });
+ } catch (error) {
+ console.error(`Failed to get imports for site ${siteId}:`, error);
+ throw new Error(`Failed to get imports for site: ${error instanceof Error ? error.message : "Unknown error"}`);
+ }
}
}