Cleanup and fix http error handling, addressed by #3
https://github.com/micromata/swd/issues/3
This commit is contained in:
parent
94e101cabd
commit
76c23dc14b
1 changed files with 7 additions and 12 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue