You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RecoveryWithWritter has signature func(w io.Writer, recovery ...gin.RecoveryFunc) but only applies the first func from recovery.
If no RecoveryFuncs were passed, it uses the defaultHandleRecovery func.
If I want to register multiple RecoveryFuncs, it would seem plausible to apply them all at once, but with this implementation most would get discarded silently. Additionally, this results in a panicking request returning code 200 instead of the pre-configured code 500.
I don't see why it couldn't allow multiple RecoveryFuncs with each handling the error separately. Alternatively I would appreciate it if the documentation gave hints to this being the intended behavior.
How to reproduce
Here's the excerpt from the gin package (recover.go:43)
// RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.funcRecoveryWithWriter(out io.Writer, recovery...RecoveryFunc) HandlerFunc {
iflen(recovery) >0 {
returnCustomRecoveryWithWriter(out, recovery[0])
}
returnCustomRecoveryWithWriter(out, defaultHandleRecovery)
}
Expectations
funcPrintErr(_*gin.Context, errany) {
iferr!=nil {
fmt.Println(err)
}
}
funcAbort(ctx*gin.Context, _any) {
ctx.AbortWithStatus(500)
}
// ...router.Use(RecoveryWithWriter(logger, PrintErr, Abort)) // -> should print the err and abort the request
## ActualresultUnderthecurrentimplementationonlytheerrorwouldgetlogged, withtherequeststillreturning200after recovering.
## Environment-goversion: go1.22.6-ginversion (orcommitref): github.com/gin-gonic/ginv1.9.1-operating system: macOS
The text was updated successfully, but these errors were encountered:
Yeah, that's what I assumed. Couldn't you put that in the documentation to limit the risk? Either that or changing it to allow multiple RecoveryFuncs. I still don't really see why since they don't interfere with each other.
Description
RecoveryWithWritter has signature func(w io.Writer, recovery ...gin.RecoveryFunc) but only applies the first func from recovery.
If no RecoveryFuncs were passed, it uses the defaultHandleRecovery func.
If I want to register multiple RecoveryFuncs, it would seem plausible to apply them all at once, but with this implementation most would get discarded silently. Additionally, this results in a panicking request returning code 200 instead of the pre-configured code 500.
I don't see why it couldn't allow multiple RecoveryFuncs with each handling the error separately. Alternatively I would appreciate it if the documentation gave hints to this being the intended behavior.
How to reproduce
Here's the excerpt from the gin package (recover.go:43)
Expectations
The text was updated successfully, but these errors were encountered: