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 {
|
func wrapRecovery(handler http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
|
||||||
defer func() {
|
defer func() {
|
||||||
r := recover()
|
if err := recover(); err != nil {
|
||||||
switch t := r.(type) {
|
switch t := err.(type) {
|
||||||
case string:
|
case string:
|
||||||
err = errors.New(t)
|
log.WithError(errors.New(t)).Error("An error occurred handling a webdav request")
|
||||||
case error:
|
case error:
|
||||||
err = t
|
log.WithError(t).Error("An error occurred handling a webdav request")
|
||||||
default:
|
}
|
||||||
err = errors.New("Unknown error")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithError(err).Error("An error occurred handling a webdav request")
|
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
Loading…
Reference in a new issue