79574952

Date: 2025-04-15 10:46:18
Score: 0.5
Natty:
Report link

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)
    }
}
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Marc