diff options
| author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-04-01 16:18:37 +0200 | 
|---|---|---|
| committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-04-01 16:18:37 +0200 | 
| commit | f01369628016ba3038cccac77ba54bcd6be6630b (patch) | |
| tree | 1cffbb8d1fc508640538d67905b0b37224eaddf6 | |
| parent | 5217357b4635fad76ca35e655517387f61ccbb2a (diff) | |
| download | jnfilter-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 "/"
| -rw-r--r-- | main.go | 18 | 
1 files changed, 15 insertions, 3 deletions
| @@ -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 | 
