From d28f00eb204e9690b338b4c88d9dbca604edb396 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Thu, 4 Sep 2025 18:24:02 +0000 Subject: [PATCH] fix: resolve 404 error when updating or deleting webhooks - Fixed webhook ID extraction in UpdateWebhook and DeleteWebhook handlers - Previous code expected 5 URL parts but path only had 2 after prefix stripping - Now correctly extracts webhook ID from /api/notifications/webhooks/{id} - Resolves frontend error when saving webhook changes --- internal/api/notifications.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/api/notifications.go b/internal/api/notifications.go index 83c6b3e08..c71ca929b 100644 --- a/internal/api/notifications.go +++ b/internal/api/notifications.go @@ -136,12 +136,14 @@ func (h *NotificationHandlers) CreateWebhook(w http.ResponseWriter, r *http.Requ // UpdateWebhook updates an existing webhook func (h *NotificationHandlers) UpdateWebhook(w http.ResponseWriter, r *http.Request) { // Extract webhook ID from URL path - parts := strings.Split(r.URL.Path, "/") - if len(parts) < 5 { - http.Error(w, "Invalid URL", http.StatusBadRequest) + // Path is like /api/notifications/webhooks/{id} after routing + path := strings.TrimPrefix(r.URL.Path, "/api/notifications/webhooks/") + webhookID := path + + if webhookID == "" { + http.Error(w, "Invalid URL - missing webhook ID", http.StatusBadRequest) return } - webhookID := parts[len(parts)-1] // Read the raw body to preserve all fields bodyBytes, err := io.ReadAll(r.Body) @@ -186,12 +188,14 @@ func (h *NotificationHandlers) UpdateWebhook(w http.ResponseWriter, r *http.Requ // DeleteWebhook deletes a webhook func (h *NotificationHandlers) DeleteWebhook(w http.ResponseWriter, r *http.Request) { // Extract webhook ID from URL path - parts := strings.Split(r.URL.Path, "/") - if len(parts) < 5 { - http.Error(w, "Invalid URL", http.StatusBadRequest) + // Path is like /api/notifications/webhooks/{id} after routing + path := strings.TrimPrefix(r.URL.Path, "/api/notifications/webhooks/") + webhookID := path + + if webhookID == "" { + http.Error(w, "Invalid URL - missing webhook ID", http.StatusBadRequest) return } - webhookID := parts[len(parts)-1] if err := h.monitor.GetNotificationManager().DeleteWebhook(webhookID); err != nil { http.Error(w, err.Error(), http.StatusNotFound)