Skip to content

Commit

Permalink
Handle errors in HTML template execution
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed Apr 5, 2019
1 parent 4ec8614 commit 293d130
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dashboard

import (
"bytes"
"encoding/json"
"html/template"
"net/http"
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 293d130

Please sign in to comment.