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:
김은빈
2024-02-28 01:39:51 +09:00
committed by GitHub
parent a7fbe3c6dc
commit 96dfb385ca
36 changed files with 260 additions and 255 deletions

View File

@ -18,7 +18,7 @@ import (
func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
queryReader, err := util.NewURLQueryReader(c.Req.URL)
if err != nil {
c.Handle(hs.Cfg, 400, "Render parameters error", err)
c.Handle(hs.Cfg, http.StatusBadRequest, "Render parameters error", err)
return
}
@ -36,7 +36,7 @@ func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
timeout, err := strconv.Atoi(queryReader.Get("timeout", "60"))
if err != nil {
c.Handle(hs.Cfg, 400, "Render parameters error", fmt.Errorf("cannot parse timeout as int: %s", err))
c.Handle(hs.Cfg, http.StatusBadRequest, "Render parameters error", fmt.Errorf("cannot parse timeout as int: %s", err))
return
}
@ -79,11 +79,11 @@ func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
}, nil)
if err != nil {
if errors.Is(err, rendering.ErrTimeout) {
c.Handle(hs.Cfg, 500, err.Error(), err)
c.Handle(hs.Cfg, http.StatusInternalServerError, err.Error(), err)
return
}
c.Handle(hs.Cfg, 500, "Rendering failed.", err)
c.Handle(hs.Cfg, http.StatusInternalServerError, "Rendering failed.", err)
return
}