Alerting: Return proper status code when trying to create alert notification channel with duplicate name or uid (#28043)

* Alerting: Return proper status code when trying to create an Alert Notification where the name or UID already exists.

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
jgulick48
2020-10-20 13:53:48 +02:00
committed by GitHub
co-authored by Arve Knudsen
parent d13c6b4c5a
commit 5bc6c447e3
3 changed files with 8 additions and 2 deletions
+4
View File
@@ -1,6 +1,7 @@
package api
import (
"errors"
"fmt"
"strconv"
@@ -273,6 +274,9 @@ func CreateAlertNotification(c *models.ReqContext, cmd models.CreateAlertNotific
cmd.OrgId = c.OrgId
if err := bus.Dispatch(&cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationWithSameNameExists) || errors.Is(err, models.ErrAlertNotificationWithSameUIDExists) {
return Error(409, "Failed to create alert notification", err)
}
return Error(500, "Failed to create alert notification", err)
}