| 214 | } |
| 215 | |
| 216 | func ErrorHandler() gin.HandlerFunc { |
| 217 | return func(c *gin.Context) { |
| 218 | c.Next() |
| 219 | if len(c.Errors) > 0 { |
| 220 | for _, err := range c.Errors { |
| 221 | event := log.Debug() |
| 222 | if httputils.IsUnexpectedError(err) { |
| 223 | event = log.Error() |
| 224 | } |
| 225 | event.Err(err.Err).Str("uri", c.Request.RequestURI).Msg("Internal error") |
| 226 | } |
| 227 | if !c.IsWebsocket() { |
| 228 | c.JSON(http.StatusInternalServerError, apitypes.Error("Internal server error")) |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | func ErrorLoggingMiddleware() gin.HandlerFunc { |
| 235 | return gin.CustomRecoveryWithWriter(nil, func(c *gin.Context, err any) { |