Alerting: Template API to return errutil errors (#91821)

This commit is contained in:
Yuri Tseretyan
2024-08-13 10:59:19 -04:00
committed by GitHub
parent 9067797eb4
commit db33df5041
11 changed files with 104 additions and 65 deletions
@@ -19,6 +19,7 @@ var (
ErrTimeIntervalInUse = errutil.Conflict("alerting.notifications.time-intervals.used").MustTemplate("Time interval is used")
ErrTemplateNotFound = errutil.NotFound("alerting.notifications.templates.notFound")
ErrTemplateInvalid = errutil.BadRequest("alerting.notifications.templates.invalidFormat").MustTemplate("Invalid format of the submitted template", errutil.WithPublic("Template is in invalid format. Correct the payload and try again."))
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."))
@@ -54,3 +55,15 @@ func MakeErrTimeIntervalInUse(usedByRoutes bool, rules []models.AlertRuleKey) er
Error: nil,
})
}
// MakeErrTimeIntervalInvalid creates an error with the ErrTimeIntervalInvalid template
func MakeErrTemplateInvalid(err error) error {
data := errutil.TemplateData{
Public: map[string]interface{}{
"Error": err.Error(),
},
Error: err,
}
return ErrTemplateInvalid.Build(data)
}