2018-01-26 08:43:53 +01:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"runtime/debug"
|
|
|
|
|
2019-05-15 18:18:54 +02:00
|
|
|
"github.com/zom-bi/ovpn-certman/handlers"
|
2018-01-26 08:43:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Recoverer Listens for panic() calls and logs the stacktrace.
|
|
|
|
func Recoverer(next http.Handler) http.Handler {
|
|
|
|
fn := func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
defer func() {
|
|
|
|
if rvr := recover(); rvr != nil {
|
|
|
|
log.Println(rvr)
|
|
|
|
log.Println(string(debug.Stack()))
|
|
|
|
handlers.ErrorHandler(w, r)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
return http.HandlerFunc(fn)
|
|
|
|
}
|