From c82d7c2dd2a61ba14c0e43361e43a5b0bbe7eaed Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 6 Jul 2015 23:37:27 -0600 Subject: [PATCH] templates: Better error handling for missing files --- middleware/templates/templates.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/middleware/templates/templates.go b/middleware/templates/templates.go index 81dcdb3a..fc4f8242 100644 --- a/middleware/templates/templates.go +++ b/middleware/templates/templates.go @@ -4,6 +4,7 @@ package templates import ( "bytes" "net/http" + "os" "path" "path/filepath" "text/template" @@ -35,6 +36,11 @@ func (t Templates) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error // Build the template tpl, err := template.ParseFiles(filepath.Join(t.Root, fpath)) if err != nil { + if os.IsNotExist(err) { + return http.StatusNotFound, nil + } else if os.IsPermission(err) { + return http.StatusForbidden, nil + } return http.StatusInternalServerError, err }