Clean backend debug logging and standardize error reporting.

This removes verbose trace output in handlers/services and keeps only actionable error-level logs.
This commit is contained in:
2026-03-09 22:18:53 +08:00
parent 4d8f2ec997
commit 4c0177149a
13 changed files with 8 additions and 163 deletions

View File

@@ -2,7 +2,6 @@ package handler
import (
"context"
"fmt"
"strconv"
"github.com/gin-gonic/gin"
@@ -145,14 +144,11 @@ func (h *MessageHandler) GetConversationByID(c *gin.Context) {
}
conversationIDStr := c.Param("id")
fmt.Printf("[DEBUG] GetConversationByID: conversationIDStr = %s\n", conversationIDStr)
conversationID, err := service.ParseConversationID(conversationIDStr)
if err != nil {
fmt.Printf("[DEBUG] GetConversationByID: failed to parse conversation ID: %v\n", err)
response.BadRequest(c, "invalid conversation id")
return
}
fmt.Printf("[DEBUG] GetConversationByID: conversationID = %s\n", conversationID)
conv, err := h.chatService.GetConversationByID(c.Request.Context(), conversationID, userID)
if err != nil {
@@ -281,14 +277,11 @@ func (h *MessageHandler) SendMessage(c *gin.Context) {
}
conversationIDStr := c.Param("id")
fmt.Printf("[DEBUG] SendMessage: conversationIDStr = %s\n", conversationIDStr)
conversationID, err := service.ParseConversationID(conversationIDStr)
if err != nil {
fmt.Printf("[DEBUG] SendMessage: failed to parse conversation ID: %v\n", err)
response.BadRequest(c, "invalid conversation id")
return
}
fmt.Printf("[DEBUG] SendMessage: conversationID = %s, userID = %s\n", conversationID, userID)
var req dto.SendMessageRequest
if err := c.ShouldBindJSON(&req); err != nil {
@@ -507,11 +500,8 @@ func (h *MessageHandler) MarkAsRead(c *gin.Context) {
// GET /api/conversations/unread/count
func (h *MessageHandler) GetUnreadCount(c *gin.Context) {
userID := c.GetString("user_id")
// 添加调试日志
fmt.Printf("[DEBUG] GetUnreadCount: user_id from context = %q\n", userID)
if userID == "" {
fmt.Printf("[DEBUG] GetUnreadCount: user_id is empty, returning 401\n")
response.Unauthorized(c, "")
return
}