- Created `qa-test-output-after-fix.txt` and `qa-test-output.txt` to log results of certificate page authentication tests. - Added `build.sh` for deterministic backend builds in CI, utilizing `go list` for efficiency. - Introduced `codeql_scan.sh` for CodeQL database creation and analysis for Go and JavaScript/TypeScript. - Implemented `dockerfile_check.sh` to validate Dockerfiles for base image and package manager mismatches. - Added `sourcery_precommit_wrapper.sh` to facilitate Sourcery CLI usage in pre-commit hooks.
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()
|
|
}
|
|
}
|