处理返回编码未设置的问题

This commit is contained in:
2025-12-20 10:23:50 +08:00
parent 7a8aac1f73
commit e907315afa
2 changed files with 12 additions and 4 deletions

View File

@@ -111,12 +111,14 @@ func handleError(c *fiber.Ctx, err error, logger *zap.Logger) error {
}
// 6. 返回统一 JSON 响应
return c.Status(httpStatus).JSON(fiber.Map{
errResp := c.Status(httpStatus).JSON(fiber.Map{
"code": code,
"data": nil,
"msg": message,
"timestamp": time.Now().Format(time.RFC3339),
})
c.Set(fiber.HeaderContentType, "application/json; charset=utf-8")
return errResp
}
// safeLog 安全地记录日志,日志失败时静默处理(默认 Error 级别)