This commit is contained in:
DeveloperDurp 2026-03-18 05:33:42 -05:00
parent c59d09e4c9
commit 0284512e36
10 changed files with 274 additions and 301 deletions

29
middleware/recover.go Normal file
View file

@ -0,0 +1,29 @@
package middleware
import (
"log"
"net/http"
"runtime/debug"
"gitlab.com/durfy/durpify/handlers"
)
func Recovery(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
msg := "Caught panic: %v, Stack trace: %s"
log.Printf(msg, err, string(debug.Stack()))
resp := handlers.NewFailureResponse(
"Unternal Server Error",
http.StatusInternalServerError,
[]string{err.(string)},
)
resp.SendReponse(w, r)
return
}
}()
next.ServeHTTP(w, r)
})
}