diff --git a/server/database-storage.ts b/server/database-storage.ts index ce9a066..d3c113c 100644 --- a/server/database-storage.ts +++ b/server/database-storage.ts @@ -105,7 +105,14 @@ export class DatabaseStorage implements IStorage { } async getAllDomains(): Promise { - return await db.select().from(domains); + try { + return await db.select().from(domains); + } catch (error) { + console.error("Error fetching domains:", error); + // If there's an error with the database query, + // return an empty array rather than throwing an exception + return []; + } } async createDomain(domain: InsertDomain): Promise { diff --git a/server/routes.ts b/server/routes.ts index 902bfe4..cbd80a2 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -889,10 +889,14 @@ export async function registerRoutes(app: Express): Promise { app.post("/api/webhooks", requireRole(["admin", "manager"]), async (req, res) => { try { - const validatedData = insertWebhookSchema.parse(req.body); + // Merge request body with user ID before validation + const requestData = { + ...req.body, + createdBy: req.user?.id // Add the user who created it + }; - // Add the user who created it - validatedData.createdBy = req.user!.id; + // Then validate the complete data + const validatedData = insertWebhookSchema.parse(requestData); // Check authorization for non-admin users if (req.user?.role !== "admin" && validatedData.organizationId !== req.user?.organizationId) { @@ -903,6 +907,7 @@ export async function registerRoutes(app: Express): Promise { res.status(201).json(webhook); } catch (error) { if (error instanceof z.ZodError) { + console.error("Validation error:", error.errors); res.status(400).json({ message: "Validation error", errors: error.errors }); } else { console.error("Error creating webhook:", error);