Cleanup and fix http error handling, addressed by #3

https://github.com/micromata/swd/issues/3
This commit is contained in:
Christian Claus 2018-04-24 17:08:57 +02:00
parent 94e101cabd
commit 76c23dc14b

View file

@ -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)