From a80f31a5c897116cd11cf8c84509419f3eb01c39 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Mon, 5 Apr 2021 17:03:00 +0300 Subject: [PATCH] Alerting: 404 error status when no alertmanager configuration (#32651) --- pkg/services/ngalert/api/api_alertmanager.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/services/ngalert/api/api_alertmanager.go b/pkg/services/ngalert/api/api_alertmanager.go index f4874d64d01..a0c857ab4c2 100644 --- a/pkg/services/ngalert/api/api_alertmanager.go +++ b/pkg/services/ngalert/api/api_alertmanager.go @@ -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) }