fix(subscribe): improve error handling and logging for subscription requests

This commit is contained in:
Chang lue Tsen 2025-08-17 10:01:12 -04:00
parent 6580cc9d44
commit 5d80d95568
3 changed files with 9 additions and 2 deletions

View File

@ -45,6 +45,7 @@ func SubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
l := subscribe.NewSubscribeLogic(c, svcCtx) l := subscribe.NewSubscribeLogic(c, svcCtx)
resp, err := l.Handler(&req) resp, err := l.Handler(&req)
if err != nil { if err != nil {
c.String(http.StatusInternalServerError, "Internal Server")
return return
} }
c.Header("subscription-userinfo", resp.Header) c.Header("subscription-userinfo", resp.Header)

View File

@ -44,6 +44,9 @@ func LoggerMiddleware(svc *svc.ServiceContext) func(c *gin.Context) {
// Start recording logs // Start recording logs
cost := time.Since(start) cost := time.Since(start)
responseStatus := c.Writer.Status() responseStatus := c.Writer.Status()
host := c.Request.Host
logs := []logger.LogField{ logs := []logger.LogField{
{ {
Key: "status", Key: "status",
@ -51,7 +54,7 @@ func LoggerMiddleware(svc *svc.ServiceContext) func(c *gin.Context) {
}, },
{ {
Key: "request", Key: "request",
Value: c.Request.Method + " " + c.Request.URL.String(), Value: c.Request.Method + " " + host + c.Request.URL.String(),
}, },
{ {
Key: "query", Key: "query",
@ -88,6 +91,10 @@ func LoggerMiddleware(svc *svc.ServiceContext) func(c *gin.Context) {
} else { } else {
logger.WithContext(c.Request.Context()).Infow("HTTP Request", logs...) logger.WithContext(c.Request.Context()).Infow("HTTP Request", logs...)
} }
if responseStatus == 404 {
logger.WithContext(c.Request.Context()).Debugf("404 Not Found: Host:%s Path:%s IsPanDomain:%v", host, c.Request.URL.Path, svc.Config.Subscribe.PanDomain)
}
} }
} }

View File

@ -14,7 +14,6 @@ func PanDomainMiddleware(svc *svc.ServiceContext) func(c *gin.Context) {
return func(c *gin.Context) { return func(c *gin.Context) {
if svc.Config.Subscribe.PanDomain && c.Request.URL.Path == "/" { if svc.Config.Subscribe.PanDomain && c.Request.URL.Path == "/" {
// intercept browser // intercept browser
ua := c.GetHeader("User-Agent") ua := c.GetHeader("User-Agent")