Commit c82d7c2d authored by Matthew Holt's avatar Matthew Holt

templates: Better error handling for missing files

parent 553d76da
...@@ -4,6 +4,7 @@ package templates ...@@ -4,6 +4,7 @@ package templates
import ( import (
"bytes" "bytes"
"net/http" "net/http"
"os"
"path" "path"
"path/filepath" "path/filepath"
"text/template" "text/template"
...@@ -35,6 +36,11 @@ func (t Templates) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error ...@@ -35,6 +36,11 @@ func (t Templates) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// Build the template // Build the template
tpl, err := template.ParseFiles(filepath.Join(t.Root, fpath)) tpl, err := template.ParseFiles(filepath.Join(t.Root, fpath))
if err != nil { if err != nil {
if os.IsNotExist(err) {
return http.StatusNotFound, nil
} else if os.IsPermission(err) {
return http.StatusForbidden, nil
}
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment