This commit is contained in:
2026-08-16 15:11:38 +08:00
parent f7f6db8695
commit a85477be80
40 changed files with 761 additions and 144 deletions
+8 -3
View File
@@ -1,6 +1,7 @@
package middleware
import (
"bytes"
"encoding/json"
"strings"
@@ -16,14 +17,18 @@ import (
// system errors and therefore are not inserted into sys_error.
func ErrorAudit(audit *service.AuditRecorder) gin.HandlerFunc {
return func(c *gin.Context) {
writer := &captureWriter{ResponseWriter: c.Writer, maxBytes: 1 << 20}
c.Writer = writer
c.Next()
if strings.Contains(c.Request.URL.Path, "/sysError/") || c.Writer.Status() >= 300 && c.Writer.Status() < 500 {
return
}
var response httpx.Response
if json.Unmarshal(writer.body.Bytes(), &response) != nil || response.Code == httpx.CodeSuccess || expectedClientFailure(response.Msg) {
var body []byte
if value, ok := c.Get(ctxRespBufferKey); ok {
if buffer, valid := value.(*bytes.Buffer); valid {
body = buffer.Bytes()
}
}
if json.Unmarshal(body, &response) != nil || response.Code == httpx.CodeSuccess || expectedClientFailure(response.Msg) {
return
}
requestID, _ := c.Get("request_id")