Merge pull request #49 from reactiveops/bb/handle-template-errors

Handle errors in HTML template execution
This commit is contained in:
Rob Scott
2019-04-05 15:08:16 -04:00
committed by GitHub

View File

@@ -1,6 +1,7 @@
package dashboard
import (
"bytes"
"encoding/json"
"html/template"
"net/http"
@@ -47,10 +48,13 @@ func MainHandler(w http.ResponseWriter, r *http.Request, c conf.Configuration, k
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = template.Must(tmpl.Clone()).Execute(w, templateData)
buf := &bytes.Buffer{}
err = template.Must(tmpl.Clone()).Execute(buf, templateData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
} else {
buf.WriteTo(w)
}
}