merge: integrate http-handler-abort-error architecture refactor

Resolve user package conflicts by keeping main's service-layer logics and
applying Abort* error handling in routers. Align oauth callback with
listener.EmitAdminLoggedIn from main.
This commit is contained in:
ryan
2026-06-18 10:53:03 +08:00
61 changed files with 2030 additions and 1686 deletions
+2 -25
View File
@@ -7,7 +7,6 @@ package router
import (
"context"
"errors"
"net/http"
"strconv"
"strings"
@@ -106,29 +105,7 @@ func corsMiddleware() gin.HandlerFunc {
}
}
// errorHandlerMiddleware 捕获 c.Errors 并统一格式化为 JSON 返回给客户端,同时将其记录到 Span 异常中
// errorHandlerMiddleware 委托给 response.ErrorHandlerMiddleware,保持路由层单一入口。
func errorHandlerMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
if len(c.Errors) > 0 {
err := c.Errors.Last().Err
span := trace.SpanFromContext(c.Request.Context())
// 1. 如果有活跃的 Span,将错误信息记录到 Trace 中,并把 Span 状态置为 Error
if span.IsRecording() {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
// 2. 将错误转化为统一的 JSON 格式响应给客户端
var apiErr *response.APIError
if errors.As(err, &apiErr) {
c.JSON(apiErr.Code, response.Err(apiErr.Msg))
} else {
// 兜底策略:未知的系统级错误
c.JSON(http.StatusInternalServerError, response.Err("内部系统错误"))
}
}
}
return response.ErrorHandlerMiddleware()
}