Fix 404 being reported as 500.

This commit is contained in:
Catherine
2025-09-15 12:04:54 +00:00
parent 44d72eea9a
commit 9d02387f5d

View File

@@ -50,7 +50,6 @@ func getPage(w http.ResponseWriter, r *http.Request) error {
// if whatever we were serving doesn't exist, try to serve `$root/404.html`
if errors.Is(err, os.ErrNotExist) {
file, _ = securejoin.OpenInRoot(config.DataDir, filepath.Join(wwwRoot, "404.html"))
err = fmt.Errorf("not found: %s", err.(*os.PathError).Path)
}
// acquire read capability to the file being served (if possible)
@@ -249,6 +248,9 @@ func ServePages(w http.ResponseWriter, r *http.Request) {
err = fmt.Errorf("method %s not allowed", r.Method)
}
if err != nil {
if pathErr, ok := err.(*os.PathError); ok {
err = fmt.Errorf("not found: %s", pathErr.Path)
}
log.Println("pages err:", err)
}
}