aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-04-01 16:18:37 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-04-01 16:18:37 +0200
commitf01369628016ba3038cccac77ba54bcd6be6630b (patch)
tree1cffbb8d1fc508640538d67905b0b37224eaddf6 /main.go
parent5217357b4635fad76ca35e655517387f61ccbb2a (diff)
downloadjnfilter-f01369628016ba3038cccac77ba54bcd6be6630b.tar.gz
jnfilter-f01369628016ba3038cccac77ba54bcd6be6630b.tar.bz2
jnfilter-f01369628016ba3038cccac77ba54bcd6be6630b.zip
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 "/"
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files 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<serie>.+) (?P<number>[0-9abc]+) \- (?P<title>.+)`)
+ 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