Better handling for not found cases, and test

This commit is contained in:
2021-10-04 13:27:46 +10:30
parent 87acf0aefb
commit dd79dbed1d
2 changed files with 66 additions and 2 deletions

View File

@@ -56,7 +56,11 @@ func getStatic(w http.ResponseWriter, r *http.Request) {
t, err := template.ParseFS(webFS, "data/wrapper.tmpl", "data/"+path)
if err != nil {
panic(err)
log.Printf("when fetching: %s got: %s", path, err)
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("not found"))
return
}
log.Printf("req: %s", r.URL.Path)
@@ -78,7 +82,11 @@ func getStatic(w http.ResponseWriter, r *http.Request) {
otherStatic, err := webFS.ReadFile("data/" + path)
if err != nil {
log.Fatalf("problem with '%s': %v", path, err)
log.Printf("when fetching: %s got: %s", path, err)
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("not found"))
return
}
w.Header().Set("Content-Type", mime.TypeByExtension(extension))