Files
stfs/internal/handlers/panic.go
2021-12-28 21:59:36 +01:00

25 lines
498 B
Go

package handlers
import (
"fmt"
"net/http"
"github.com/pojntfx/stfs/internal/logging"
)
func PanicHandler(h http.Handler, log *logging.JSONLogger) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
http.Error(w, fmt.Sprintf("%v", err), http.StatusInternalServerError)
log.Error("Error during HTTP request", map[string]interface{}{
"err": err,
})
}
}()
h.ServeHTTP(w, r)
})
}