Alerting: 404 error status when no alertmanager configuration (#32651)

This commit is contained in:
Sofia Papagiannaki 2021-04-05 17:03:00 +03:00 committed by GitHub
parent bc60991fae
commit a80f31a5c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,14 +60,15 @@ func (srv AlertmanagerSrv) RouteDeleteSilence(c *models.ReqContext) response.Res
func (srv AlertmanagerSrv) RouteGetAlertingConfig(c *models.ReqContext) response.Response {
query := ngmodels.GetLatestAlertmanagerConfigurationQuery{}
err := srv.store.GetLatestAlertmanagerConfiguration(&query)
if err != nil {
if err := srv.store.GetLatestAlertmanagerConfiguration(&query); err != nil {
if errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
return response.Error(http.StatusNotFound, err.Error(), nil)
}
return response.Error(http.StatusInternalServerError, "failed to get latest configuration", err)
}
cfg := apimodels.PostableUserConfig{}
err = yaml.Unmarshal([]byte(query.Result.AlertmanagerConfiguration), &cfg)
if err != nil {
if err := yaml.Unmarshal([]byte(query.Result.AlertmanagerConfiguration), &cfg); err != nil {
return response.Error(http.StatusInternalServerError, "failed to unmarshal alertmanager configuration", err)
}