mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 03:11:01 -06:00
Alerting: Alert rule constraint violations return as 400s in provisioning API (#76396)
Constraint violations become 400s
This commit is contained in:
parent
b04a014341
commit
39599fa7f7
@ -330,6 +330,9 @@ func (srv *ProvisioningSrv) RoutePostAlertRule(c *contextmodel.ReqContext, ar de
|
|||||||
return ErrResp(http.StatusBadRequest, err, "")
|
return ErrResp(http.StatusBadRequest, err, "")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, alerting_models.ErrAlertRuleUniqueConstraintViolation) {
|
||||||
|
return ErrResp(http.StatusBadRequest, err, "")
|
||||||
|
}
|
||||||
if errors.Is(err, store.ErrOptimisticLock) {
|
if errors.Is(err, store.ErrOptimisticLock) {
|
||||||
return ErrResp(http.StatusConflict, err, "")
|
return ErrResp(http.StatusConflict, err, "")
|
||||||
}
|
}
|
||||||
@ -352,6 +355,9 @@ func (srv *ProvisioningSrv) RoutePutAlertRule(c *contextmodel.ReqContext, ar def
|
|||||||
updated.UID = UID
|
updated.UID = UID
|
||||||
provenance := determineProvenance(c)
|
provenance := determineProvenance(c)
|
||||||
updatedAlertRule, err := srv.alertRules.UpdateAlertRule(c.Req.Context(), updated, alerting_models.Provenance(provenance))
|
updatedAlertRule, err := srv.alertRules.UpdateAlertRule(c.Req.Context(), updated, alerting_models.Provenance(provenance))
|
||||||
|
if errors.Is(err, alerting_models.ErrAlertRuleUniqueConstraintViolation) {
|
||||||
|
return ErrResp(http.StatusBadRequest, err, "")
|
||||||
|
}
|
||||||
if errors.Is(err, alerting_models.ErrAlertRuleNotFound) {
|
if errors.Is(err, alerting_models.ErrAlertRuleNotFound) {
|
||||||
return response.Empty(http.StatusNotFound)
|
return response.Empty(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
@ -473,6 +479,9 @@ func (srv *ProvisioningSrv) RoutePutAlertRuleGroup(c *contextmodel.ReqContext, a
|
|||||||
}
|
}
|
||||||
provenance := determineProvenance(c)
|
provenance := determineProvenance(c)
|
||||||
err = srv.alertRules.ReplaceRuleGroup(c.Req.Context(), c.SignedInUser.GetOrgID(), groupModel, c.UserID, alerting_models.Provenance(provenance))
|
err = srv.alertRules.ReplaceRuleGroup(c.Req.Context(), c.SignedInUser.GetOrgID(), groupModel, c.UserID, alerting_models.Provenance(provenance))
|
||||||
|
if errors.Is(err, alerting_models.ErrAlertRuleUniqueConstraintViolation) {
|
||||||
|
return ErrResp(http.StatusBadRequest, err, "")
|
||||||
|
}
|
||||||
if errors.Is(err, alerting_models.ErrAlertRuleFailedValidation) {
|
if errors.Is(err, alerting_models.ErrAlertRuleFailedValidation) {
|
||||||
return ErrResp(http.StatusBadRequest, err, "")
|
return ErrResp(http.StatusBadRequest, err, "")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user