From 3f5a2c5041f607f07d0d752ca9db4387781f1bfc Mon Sep 17 00:00:00 2001 From: rramiachraf <51409801+rramiachraf@users.noreply.github.com> Date: Sun, 22 Jan 2023 16:44:22 +0100 Subject: [PATCH] feat: add custom error page for unmatched routes --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 50501ef..7363f74 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,14 @@ func main() { r.HandleFunc("/{id}-lyrics", lyricsHandler) r.HandleFunc("/images/{filename}.{ext}", proxyHandler) r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) + render("error", w, map[string]string{ + "Status": "404", + "Error": "page not found", + }) + + }) server := &http.Server{ Handler: r,