This commit is contained in:
kevin
2020-07-29 18:00:04 +08:00
parent 121323b8c3
commit ca3934582a
58 changed files with 222 additions and 200 deletions

View File

@@ -0,0 +1,22 @@
package handler
import (
"fmt"
"net/http"
"runtime/debug"
"zero/ngin/internal"
)
func RecoverHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if result := recover(); result != nil {
internal.Error(r, fmt.Sprintf("%v\n%s", result, debug.Stack()))
w.WriteHeader(http.StatusInternalServerError)
}
}()
next.ServeHTTP(w, r)
})
}