mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Grafana: Replace magic number with a constant variable in response status (#80132)
* Chore: Replace response status with const var * Apply suggestions from code review Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Add net/http import --------- Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
@@ -72,16 +72,16 @@ func (srv ConfigSrv) RoutePostNGalertConfig(c *contextmodel.ReqContext, body api
|
||||
|
||||
sendAlertsTo, err := ngmodels.StringToAlertmanagersChoice(string(body.AlertmanagersChoice))
|
||||
if err != nil {
|
||||
return response.Error(400, "Invalid alertmanager choice specified", err)
|
||||
return response.Error(http.StatusBadRequest, "Invalid alertmanager choice specified", err)
|
||||
}
|
||||
|
||||
externalAlertmanagers, err := srv.externalAlertmanagers(c.Req.Context(), c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
return response.Error(500, "Couldn't fetch the external Alertmanagers from datasources", err)
|
||||
return response.Error(http.StatusInternalServerError, "Couldn't fetch the external Alertmanagers from datasources", err)
|
||||
}
|
||||
|
||||
if sendAlertsTo == ngmodels.ExternalAlertmanagers && len(externalAlertmanagers) < 1 {
|
||||
return response.Error(400, "At least one Alertmanager must be provided or configured as a datasource that handles alerts to choose this option", nil)
|
||||
return response.Error(http.StatusBadRequest, "At least one Alertmanager must be provided or configured as a datasource that handles alerts to choose this option", nil)
|
||||
}
|
||||
|
||||
cfg := &ngmodels.AdminConfiguration{
|
||||
|
||||
@@ -604,11 +604,11 @@ func exportHcl(download bool, body definitions.AlertingFileExport) response.Resp
|
||||
return nil
|
||||
}
|
||||
if err := convertToResources(); err != nil {
|
||||
return response.Error(500, "failed to convert to HCL resources", err)
|
||||
return response.Error(http.StatusInternalServerError, "failed to convert to HCL resources", err)
|
||||
}
|
||||
hclBody, err := hcl.Encode(resources...)
|
||||
if err != nil {
|
||||
return response.Error(500, "body hcl encode", err)
|
||||
return response.Error(http.StatusInternalServerError, "body hcl encode", err)
|
||||
}
|
||||
resp := response.Respond(http.StatusOK, hclBody)
|
||||
if download {
|
||||
|
||||
Reference in New Issue
Block a user