You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
433 B
Go
23 lines
433 B
Go
4 years ago
|
package handler
|
||
4 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"runtime/debug"
|
||
|
|
||
4 years ago
|
"zero/ngin/internal"
|
||
4 years ago
|
)
|
||
|
|
||
|
func RecoverHandler(next http.Handler) http.Handler {
|
||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
defer func() {
|
||
|
if result := recover(); result != nil {
|
||
4 years ago
|
internal.Error(r, fmt.Sprintf("%v\n%s", result, debug.Stack()))
|
||
4 years ago
|
w.WriteHeader(http.StatusInternalServerError)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
next.ServeHTTP(w, r)
|
||
|
})
|
||
|
}
|