This commit is contained in:
Tomas Dvorak
2026-01-26 08:13:18 +01:00
parent aa036b6550
commit dfc079288f
505 changed files with 95755 additions and 5712 deletions
+21 -19
View File
@@ -5,8 +5,8 @@ import (
"net/http"
"runtime/debug"
"fotbal-club/pkg/logger"
"fotbal-club/internal/services"
"fotbal-club/pkg/logger"
"github.com/gin-gonic/gin"
)
@@ -18,27 +18,28 @@ func CustomRecovery() gin.HandlerFunc {
if err := recover(); err != nil {
// Get stack trace
stack := string(debug.Stack())
// Log the panic
requestID := GetRequestID(c)
logger.Error("Panic recovered",
"request_id", requestID,
"error", fmt.Sprintf("%v", err),
"stack", stack,
"path", c.Request.URL.Path,
"method", c.Request.Method,
)
logger.Error(fmt.Sprintf(
"Panic recovered: request_id=%s error=%v path=%s method=%s stack=%s",
requestID,
err,
c.Request.URL.Path,
c.Request.Method,
stack,
))
// Return error response
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Internal server error",
"request_id": requestID,
})
c.Abort()
}
}()
c.Next()
}
}
@@ -52,13 +53,14 @@ func CustomRecoveryWithReporter(reporter *services.ErrorReporter) gin.HandlerFun
if err := recover(); err != nil {
stack := string(debug.Stack())
requestID := GetRequestID(c)
logger.Error("Panic recovered",
"request_id", requestID,
"error", fmt.Sprintf("%v", err),
"stack", stack,
"path", c.Request.URL.Path,
"method", c.Request.Method,
)
logger.Error(fmt.Sprintf(
"Panic recovered: request_id=%s error=%v path=%s method=%s stack=%s",
requestID,
err,
c.Request.URL.Path,
c.Request.Method,
stack,
))
reporter.Report(c.Request.Context(), &services.ErrorEvent{
Origin: "backend",
Language: "go",