Fix panic when accessing nonexistent .js file in static path

This commit is contained in:
Xabier Eizmendi 2020-10-02 09:56:10 +02:00
parent 1529e796df
commit 5085baa655

View File

@ -78,7 +78,15 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, box *
data["Json"] = string(b) data["Json"] = string(b)
index := template.Must(template.New("index").Delims("[{[", "]}]").Parse(box.MustString(file))) fileContents, err := box.String(file)
if err != nil {
if err == os.ErrNotExist {
return http.StatusNotFound, err
} else {
return http.StatusInternalServerError, err
}
}
index := template.Must(template.New("index").Delims("[{[", "]}]").Parse(fileContents))
err = index.Execute(w, data) err = index.Execute(w, data)
if err != nil { if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err