mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-07-28 04:18:57 +00:00
Improve error handling and add user tracking for webhooks
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/7f30ef0d-2f71-4e3c-8bcd-86b7fce895eb.jpg
This commit is contained in:
@@ -105,7 +105,14 @@ export class DatabaseStorage implements IStorage {
|
||||
}
|
||||
|
||||
async getAllDomains(): Promise<Domain[]> {
|
||||
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<Domain> {
|
||||
|
||||
+8
-3
@@ -889,10 +889,14 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
|
||||
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<Server> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user