mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-22 19:23:31 +00:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user