fix(smallstrip,exceptions): superfulous call when responding exception after first Write

This commit is contained in:
Guz
2025-03-05 11:51:14 -03:00
parent 9055d4ad3a
commit a2452dd239

View File

@@ -141,11 +141,26 @@ func NewMiddleware(handler HandlerFunc) middleware.Middleware {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r = r.WithContext(context.WithValue(r.Context(), handlerFuncCtxKey, handler))
next.ServeHTTP(w, r)
mw := &middlewareReponseWriter{w, false}
next.ServeHTTP(mw, r)
})
}
}
type middlewareReponseWriter struct {
http.ResponseWriter
done bool
}
func (w *middlewareReponseWriter) WriteHeader(s int) {
if !w.done {
w.ResponseWriter.WriteHeader(s)
}
w.done = true
}
const handlerFuncCtxKey = "xx-smalltrip-Exception-handler-func"
type HandlerFunc = func(e Exception, w http.ResponseWriter, r *http.Request)