重构日志与可观测性体系
新增单行文本编码器与结构化 GORM 日志,统一错误记录与请求日志策略,收紧日志文件权限并修复按天切分与压缩,支付回调参数脱敏,生产强制阿里云短信,RequestID 校验防注入,日志文案中文化。
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func writeChatError(c *gin.Context, err error) {
|
||||
response.RecordError(c, err)
|
||||
switch {
|
||||
case errors.Is(err, ErrDependencyUnavailable):
|
||||
response.ServiceUnavailable(c, "聊天服务暂时不可用")
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"hfb_sys/backend/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -19,7 +21,8 @@ func (h *Handler) CreateQrCodeHandler(c *gin.Context) {
|
||||
adminID := c.GetUint64("admin_id")
|
||||
qrcode, err := h.service.repo.CreateQrCode(c.Request.Context(), adminID, req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -37,7 +40,8 @@ func (h *Handler) BatchCreateQrCodeHandler(c *gin.Context) {
|
||||
adminID := c.GetUint64("admin_id")
|
||||
qrcodes, err := h.service.repo.BatchCreateQrCode(c.Request.Context(), adminID, req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -54,7 +58,8 @@ func (h *Handler) BatchDeleteQrCodeHandler(c *gin.Context) {
|
||||
|
||||
deleted, err := h.service.repo.BatchDeleteQrCodes(c.Request.Context(), req.IDs)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -71,7 +76,8 @@ func (h *Handler) ListQrCodesHandler(c *gin.Context) {
|
||||
|
||||
qrcodes, total, err := h.service.repo.ListQrCodes(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,7 +95,8 @@ func (h *Handler) ListQrCodesHandler(c *gin.Context) {
|
||||
func (h *Handler) GetQrCodeStatsHandler(c *gin.Context) {
|
||||
stats, err := h.service.repo.GetQrCodeStats(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -124,7 +131,8 @@ func (h *Handler) RecognizeQrCodeGroupNameHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": "PaddleOCR 服务暂时不可用"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -167,7 +175,8 @@ func (h *Handler) SubmitOCRJobHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "OCR 任务不存在或已过期"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -188,7 +197,8 @@ func (h *Handler) GetOCRJobResultHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "OCR 任务不存在或已过期"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -218,7 +228,8 @@ func (h *Handler) UpdateQrCodeHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "已发放的二维码不能改回待用"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -238,7 +249,8 @@ func (h *Handler) DeleteQrCodeHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "二维码不存在"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
response.RecordError(c, err)
|
||||
response.InternalServerError(c, "聊天二维码服务暂时不可用")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user