[v10.4.x] Alerting: Return a 400 and errutil error when trying to delete a contact point that is referenced by a policy (#86162)

Alerting: Return a 400 and errutil error when trying to delete a contact point that is referenced by a policy (#85481)

Return a 400 and errutil error when trying to delete a contact point that is referenced by a policy

(cherry picked from commit 5b1498f98f)

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-04-15 09:49:15 -05:00
committed by GitHub
co-authored by Alexander Weaver
parent 2530844825
commit 2c66783f98
3 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -191,7 +191,7 @@ func (srv *ProvisioningSrv) RoutePutContactPoint(c *contextmodel.ReqContext, cp
func (srv *ProvisioningSrv) RouteDeleteContactPoint(c *contextmodel.ReqContext, UID string) response.Response {
err := srv.contactPointService.DeleteContactPoint(c.Req.Context(), c.SignedInUser.GetOrgID(), UID)
if err != nil {
return ErrResp(http.StatusInternalServerError, err, "")
return response.ErrOrFallback(http.StatusInternalServerError, "failed to delete contact point", err)
}
return response.JSON(http.StatusAccepted, util.DynMap{"message": "contactpoint deleted"})
}
@@ -338,7 +338,7 @@ func (ecp *ContactPointService) DeleteContactPoint(ctx context.Context, orgID in
}
}
if fullRemoval && isContactPointInUse(name, []*apimodels.Route{revision.cfg.AlertmanagerConfig.Route}) {
return fmt.Errorf("contact point '%s' is currently used by a notification policy", name)
return ErrContactPointReferenced
}
return ecp.xact.InTransaction(ctx, func(ctx context.Context) error {
@@ -19,6 +19,8 @@ var (
ErrTimeIntervalExists = errutil.BadRequest("alerting.notifications.time-intervals.nameExists", errutil.WithPublicMessage("Time interval with this name already exists. Use a different name or update existing one."))
ErrTimeIntervalInvalid = errutil.BadRequest("alerting.notifications.time-intervals.invalidFormat").MustTemplate("Invalid format of the submitted time interval", errutil.WithPublic("Time interval is in invalid format. Correct the payload and try again."))
ErrTimeIntervalInUse = errutil.Conflict("alerting.notifications.time-intervals.used", errutil.WithPublicMessage("Time interval is used by one or many notification policies"))
ErrContactPointReferenced = errutil.BadRequest("alerting.notifications.contact-points.referenced", errutil.WithPublicMessage("Contact point is currently referenced by a notification policy."))
)
func makeErrBadAlertmanagerConfiguration(err error) error {