From f01369628016ba3038cccac77ba54bcd6be6630b Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 1 Apr 2024 16:18:37 +0200 Subject: fix: Handle not found better (or at all) By default go tunnels every request to "/", so I'd need to check for paths at the podcast handler so I can report not found for anything other than "/" --- main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7a8d2a6..728d32c 100644 --- a/main.go +++ b/main.go @@ -31,8 +31,9 @@ type ( var ( //go:embed static/* - assets embed.FS - serieRegex = regexp.MustCompile(`(?P.+) (?P[0-9abc]+) \- (?P.+)`) + assets embed.FS + serieRegex = regexp.MustCompile(`(?P<serie>.+) (?P<number>[0-9abc]+) \- (?P<title>.+)`) + errNotFound = errors.New("not found") ) var ( @@ -164,7 +165,12 @@ func handleError(next errorRequestHandler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if err := next(w, r); err != nil { slog.ErrorContext(r.Context(), "Error", "error", err.Error()) - w.WriteHeader(http.StatusInternalServerError) + + if errors.Is(err, errNotFound) { + w.WriteHeader(http.StatusNotFound) + } else { + w.WriteHeader(http.StatusInternalServerError) + } } } } @@ -236,6 +242,12 @@ func view(w http.ResponseWriter, r *http.Request) error { } func podcast(w http.ResponseWriter, r *http.Request) error { + + if r.URL.Path != "/" { + return errNotFound + + } + xml, err := fetchXML(r.Context()) if err != nil { return err -- cgit v1.2.3