Alerting API: send 404 not found error and enrich delete with UID endpoint response with alert notification ID (#27550)
* Alerting API: Send back 404 not found error for update and delete endpoints * Alerting API: send back alert notification id for delete with uid endpoint
This commit is contained in:
+17
-9
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func ValidateOrgAlert(c *models.ReqContext) {
|
||||
@@ -287,13 +288,12 @@ func UpdateAlertNotification(c *models.ReqContext, cmd models.UpdateAlertNotific
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == models.ErrAlertNotificationNotFound {
|
||||
return Error(404, err.Error(), err)
|
||||
}
|
||||
return Error(500, "Failed to update alert notification", err)
|
||||
}
|
||||
|
||||
if cmd.Result == nil {
|
||||
return Error(404, "Alert notification not found", nil)
|
||||
}
|
||||
|
||||
query := models.GetAlertNotificationsQuery{
|
||||
OrgId: c.OrgId,
|
||||
Id: cmd.Id,
|
||||
@@ -316,13 +316,12 @@ func UpdateAlertNotificationByUID(c *models.ReqContext, cmd models.UpdateAlertNo
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == models.ErrAlertNotificationNotFound {
|
||||
return Error(404, err.Error(), nil)
|
||||
}
|
||||
return Error(500, "Failed to update alert notification", err)
|
||||
}
|
||||
|
||||
if cmd.Result == nil {
|
||||
return Error(404, "Alert notification not found", nil)
|
||||
}
|
||||
|
||||
query := models.GetAlertNotificationsWithUidQuery{
|
||||
OrgId: cmd.OrgId,
|
||||
Uid: cmd.Uid,
|
||||
@@ -390,6 +389,9 @@ func DeleteAlertNotification(c *models.ReqContext) Response {
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == models.ErrAlertNotificationNotFound {
|
||||
return Error(404, err.Error(), nil)
|
||||
}
|
||||
return Error(500, "Failed to delete alert notification", err)
|
||||
}
|
||||
|
||||
@@ -403,10 +405,16 @@ func DeleteAlertNotificationByUID(c *models.ReqContext) Response {
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == models.ErrAlertNotificationNotFound {
|
||||
return Error(404, err.Error(), nil)
|
||||
}
|
||||
return Error(500, "Failed to delete alert notification", err)
|
||||
}
|
||||
|
||||
return Success("Notification deleted")
|
||||
return JSON(200, util.DynMap{
|
||||
"message": "Notification deleted",
|
||||
"id": cmd.DeletedAlertNotificationId,
|
||||
})
|
||||
}
|
||||
|
||||
//POST /api/alert-notifications/test
|
||||
|
||||
Reference in New Issue
Block a user