sync from project
This commit is contained in:
@ -42,3 +42,20 @@ func DebugPanicHandler(w http.ResponseWriter, r *http.Request, err any) {
|
||||
func Debug() middleware.Middleware {
|
||||
return Recover(DebugPanicHandler)
|
||||
}
|
||||
|
||||
// ProductionPanicHandler is a PanicResponseFunc that provides a generic error message
|
||||
// in production environments and logs the detailed panic error.
|
||||
func ProductionPanicHandler(w http.ResponseWriter, r *http.Request, err any) {
|
||||
httplog.Logger(r).With("panic", err).Error("request panicked")
|
||||
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"error": "Internal Server Error",
|
||||
})
|
||||
}
|
||||
|
||||
// Production returns a middleware that recovers from panics and handles them
|
||||
// with ProductionPanicHandler.
|
||||
func Production() middleware.Middleware {
|
||||
return Recover(ProductionPanicHandler)
|
||||
}
|
||||
|
Reference in New Issue
Block a user