mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
21 lines
450 B
Go
21 lines
450 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
func recoveryHandler(reporter func(ctx context.Context, e interface{})) func(h http.Handler) http.Handler {
|
|
return func(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
defer func() {
|
|
if e := recover(); e != nil {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
reporter(r.Context(), e)
|
|
}
|
|
}()
|
|
h.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|