mirror of
https://gitlab.durp.info/durfy/modules/durpify.git
synced 2026-05-07 16:10:28 -05:00
update
This commit is contained in:
parent
c59d09e4c9
commit
0284512e36
10 changed files with 274 additions and 301 deletions
29
middleware/recover.go
Normal file
29
middleware/recover.go
Normal 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)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue