22 lines
444 B
Go
22 lines
444 B
Go
package middleware
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"runtime/debug"
|
|
"synlotto-website/helpers"
|
|
)
|
|
|
|
func Recover(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
defer func() {
|
|
if rec := recover(); rec != nil {
|
|
log.Printf("🔥 Recovered from panic: %v\n%s", rec, debug.Stack())
|
|
|
|
helpers.RenderError(w, r, http.StatusInternalServerError)
|
|
}
|
|
}()
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|