This commit is contained in:
lbenedar
2026-03-19 14:06:24 +03:00
parent b8fff8f7d5
commit 6736c24e19
2 changed files with 21 additions and 2 deletions

18
cmd/api/middleware.go Normal file
View File

@@ -0,0 +1,18 @@
package main
import (
"fmt"
"net/http"
)
func (app *application) recoverPanic(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
w.Header().Set("Connection", "close")
app.serverErrorResponse(w, r, fmt.Errorf("%s", err))
}
}()
next.ServeHTTP(w, r)
})
}