1diff --git a/main.go b/main.go
2index f6a2a13dffb33810cbf55aea8bc4a7a326260d79..c74136b711b6194776142c39e6dc1afd8a4bb5a2 100644
3--- a/main.go
4+++ b/main.go
5@@ -69,6 +69,10 @@ seriesCount = promauto.NewCounterVec(prometheus.CounterOpts{
6 Name: "serie_count",
7 Help: "How often a serie is called",
8 }, []string{"serie"})
9+ panicCount = promauto.NewCounter(prometheus.CounterOpts{
10+ Name: "panic",
11+ Help: "How many times the application panic",
12+ })
13 )
14
15 func getSeries(r *http.Request) []string {
16@@ -125,8 +129,10 @@ return nil, errors.New("Invalid http code")
17 }
18
19 func appendTag(tag *etree.Element, ap string) {
20- text := tag.Text()
21- tag.SetText(text + ap)
22+ if tag != nil {
23+ text := tag.Text()
24+ tag.SetText(text + ap)
25+ }
26 }
27
28 func filterBySeries(series []string, xml []byte, temper bool) ([]byte, error) {
29@@ -163,6 +169,14 @@ }
30
31 func handleError(next errorRequestHandler) http.HandlerFunc {
32 return func(w http.ResponseWriter, r *http.Request) {
33+ defer func() {
34+ if perr := recover(); perr != nil {
35+ w.WriteHeader(http.StatusInternalServerError)
36+ slog.Error("Request panic", "error", perr)
37+ panicCount.Inc()
38+ }
39+ }()
40+
41 if err := next(w, r); err != nil {
42 slog.ErrorContext(r.Context(), "Error", "error", err.Error())
43
44@@ -242,10 +256,8 @@ return nil
45 }
46
47 func podcast(w http.ResponseWriter, r *http.Request) error {
48-
49 if r.URL.Path != "/" {
50 return errNotFound
51-
52 }
53
54 xml, err := fetchXML(r.Context())
55@@ -306,9 +318,7 @@ }
56 return
57 }
58
59- var (
60- addr = flag.String("addr", ":8080", "Server address")
61- )
62+ addr := flag.String("addr", ":8080", "Server address")
63
64 flag.Parse()
65
66@@ -323,6 +333,7 @@ Handler: mux,
67 Addr: *addr,
68 }
69
70+ slog.Info("Starting server", "addr", *addr)
71 err := server.ListenAndServe()
72 if err != nil {
73 fmt.Printf("Server error: %s", err.Error())