Idiomatic way to handle template errors in golang
Say I have a html/template like the following: <html> <body> <p>{{SomeFunc .SomeData}}</p> </body> and sometimes SomeFunc returns an error. Is there an idiomatic way to deal with this? If I write directly to the ResponseWriter , then a status code 200 has already been written before I encounter the error. var tmpl *template.Template func Handler(w http.ResponseWriter, r *http.Request) { err := tmpl.Execute(w, data) // "<html><body><p>" has already been written... // what to do with err? } Preferably I would return a status code 400 or some such, but I can't see a way to do this if I use