mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
templates: Better error handling for missing files
This commit is contained in:
parent
553d76dab3
commit
c82d7c2dd2
1 changed files with 6 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue