mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 23:35:15 +08:00
Alerting: Use correct status code for UID conflict in contact point provisionining API (#98970)
Use correct status code for UID conflict in contact point provisioning API
This commit is contained in:
@ -171,7 +171,7 @@ func (srv *ProvisioningSrv) RoutePostContactPoint(c *contextmodel.ReqContext, cp
|
||||
return ErrResp(http.StatusBadRequest, err, "")
|
||||
}
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "", err)
|
||||
}
|
||||
return response.JSON(http.StatusAccepted, contactPoint)
|
||||
}
|
||||
|
@ -198,10 +198,7 @@ func (ecp *ContactPointService) CreateContactPoint(
|
||||
// check if uid is already used in receiver
|
||||
for _, rec := range receiver.PostableGrafanaReceivers.GrafanaManagedReceivers {
|
||||
if grafanaReceiver.UID == rec.UID {
|
||||
return apimodels.EmbeddedContactPoint{}, fmt.Errorf(
|
||||
"receiver configuration with UID '%s' already exist in contact point '%s'. Please use unique identifiers for receivers across all contact points",
|
||||
rec.UID,
|
||||
rec.Name)
|
||||
return apimodels.EmbeddedContactPoint{}, MakeErrContactPointUidExists(rec.UID, rec.Name)
|
||||
}
|
||||
}
|
||||
if receiver.Name == contactPoint.Name {
|
||||
|
@ -28,6 +28,10 @@ var (
|
||||
|
||||
ErrContactPointReferenced = errutil.Conflict("alerting.notifications.contact-points.referenced", errutil.WithPublicMessage("Contact point is currently referenced by a notification policy."))
|
||||
ErrContactPointUsedInRule = errutil.Conflict("alerting.notifications.contact-points.used-by-rule", errutil.WithPublicMessage("Contact point is currently used in the notification settings of one or many alert rules."))
|
||||
contactPointUidExists = "Receiver configuration with UID '{{ .Public.UID }}' already exists in contact point '{{ .Public.Name }}'. Please use unique identifiers for receivers across all contact points."
|
||||
ErrContactPointUidExists = errutil.Conflict("alerting.notifications.contact-points.uidInUse").MustTemplate(
|
||||
contactPointUidExists, errutil.WithPublic(contactPointUidExists),
|
||||
)
|
||||
|
||||
ErrRouteInvalidFormat = errutil.BadRequest("alerting.notifications.routes.invalidFormat").MustTemplate(
|
||||
"Invalid format of the submitted route.",
|
||||
@ -104,3 +108,12 @@ func MakeErrRouteInvalidFormat(err error) error {
|
||||
Error: err,
|
||||
})
|
||||
}
|
||||
|
||||
func MakeErrContactPointUidExists(uid, name string) error {
|
||||
return ErrContactPointUidExists.Build(errutil.TemplateData{
|
||||
Public: map[string]any{
|
||||
"UID": uid,
|
||||
"Name": name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user