From 12f65072f28baa34731acc2301b0dc20907924c2 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Mon, 25 Feb 2019 19:03:04 +0100 Subject: [PATCH] Log error when flushing fails --- main.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index b8e632e..93a21db 100644 --- a/main.go +++ b/main.go @@ -96,7 +96,11 @@ func (*authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - defer sess.Flush() + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() if r.Method == http.MethodGet { if r.URL.Path == "/auth/login" { @@ -204,7 +208,11 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - defer sess.Flush() + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() if !sess.LoggedIn { http.Redirect(w, r, "/", http.StatusFound) @@ -253,7 +261,11 @@ func (h *saveHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - defer sess.Flush() + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() if !sess.LoggedIn { http.Redirect(w, r, "/", http.StatusFound) @@ -280,7 +292,11 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - defer sess.Flush() + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() if !sess.LoggedIn { http.Redirect(w, r, "/", http.StatusFound) @@ -321,7 +337,11 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - defer sess.Flush() + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() page := r.URL.Path[1:] if page == "" { @@ -380,7 +400,11 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } - defer sess.Flush() + defer func() { + if err := sess.Flush(); err != nil { + log.Println(err) + } + }() if !sess.LoggedIn { http.Redirect(w, r, "/", http.StatusFound)