From 76c23dc14b01577b328a2cf59b6dca011d6d59b3 Mon Sep 17 00:00:00 2001 From: Christian Claus Date: Tue, 24 Apr 2018 17:08:57 +0200 Subject: [PATCH] Cleanup and fix http error handling, addressed by #3 https://github.com/micromata/swd/issues/3 --- cmd/swd/main.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/cmd/swd/main.go b/cmd/swd/main.go index 90efec0..0b4021c 100644 --- a/cmd/swd/main.go +++ b/cmd/swd/main.go @@ -55,20 +55,15 @@ func main() { func wrapRecovery(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var err error defer func() { - r := recover() - switch t := r.(type) { - case string: - err = errors.New(t) - case error: - err = t - default: - err = errors.New("Unknown error") + if err := recover(); err != nil { + switch t := err.(type) { + case string: + log.WithError(errors.New(t)).Error("An error occurred handling a webdav request") + case error: + log.WithError(t).Error("An error occurred handling a webdav request") + } } - - log.WithError(err).Error("An error occurred handling a webdav request") - http.Error(w, "Internal server error", http.StatusInternalServerError) }() handler.ServeHTTP(w, r)