From 5085baa6550b6209a90fb71cf0979ff87e99e29f Mon Sep 17 00:00:00 2001 From: Xabier Eizmendi Date: Fri, 2 Oct 2020 09:56:10 +0200 Subject: [PATCH] Fix panic when accessing nonexistent .js file in static path --- http/static.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/http/static.go b/http/static.go index 32ed3fa1..0bc1facc 100644 --- a/http/static.go +++ b/http/static.go @@ -78,7 +78,15 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, box * 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) if err != nil { return http.StatusInternalServerError, err