I've figured it out.
Gin adds all errors with c.Errors
, thus you need a middleware at the end that catches these errors. c.Next()
makes sure the middleware runs after the handler.
A minimal example of such a middleware:
func errorHandlingMiddleware(c *gin.Context) {
c.Next()
err := c.Errors.Last()
if err != nil {
slog.Error("Handler failed", "error", err)
}
}