- Refactored `SyncMonitors` method in `uptime_service.go` for better readability. - Updated unit tests for `UptimeService` to ensure proper functionality. - Introduced Playwright configuration for end-to-end testing. - Added e2e tests for WAF blocking and monitoring functionality. - Enhanced the Security page to include WAF mode and rule set selection. - Implemented tests for WAF configuration changes and validation. - Created a `.last-run.json` file to store test results.
33 lines
885 B
Go
33 lines
885 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"runtime/debug"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Recovery logs panic information. When verbose is true it logs stacktraces
|
|
// and basic request metadata for debugging.
|
|
func Recovery(verbose bool) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
// Try to get a request-scoped logger; fall back to global logger
|
|
entry := GetRequestLogger(c)
|
|
if verbose {
|
|
entry.WithFields(map[string]interface{}{
|
|
"method": c.Request.Method,
|
|
"path": SanitizePath(c.Request.URL.Path),
|
|
"headers": SanitizeHeaders(c.Request.Header),
|
|
}).Errorf("PANIC: %v\nStacktrace:\n%s", r, debug.Stack())
|
|
} else {
|
|
entry.Errorf("PANIC: %v", r)
|
|
}
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
|
|
}
|
|
}()
|
|
c.Next()
|
|
}
|
|
}
|