Browse Source

feat: 处理错误时 uuid 不是必须的

wangkang 2 weeks ago
parent
commit
b0181e53b2
1 changed files with 17 additions and 19 deletions
  1. 17 19
      common/common.go

+ 17 - 19
common/common.go

@@ -5,9 +5,15 @@ import (
 	"context"
 	"crypto/tls"
 	"errors"
+	"io"
+	"mime/multipart"
+	"net/http"
+	"os"
+	"strings"
+	"time"
+
 	"git.listensoft.net/tool/jspkit/common/lxhttp"
 	"git.listensoft.net/tool/jspkit/common/models"
-
 	"git.listensoft.net/tool/jspkit/common/variable"
 	"git.listensoft.net/tool/jspkit/logger"
 	"git.listensoft.net/tool/jspkit/taxerr"
@@ -15,12 +21,6 @@ import (
 	"github.com/go-rod/rod"
 	"github.com/google/uuid"
 	"go.uber.org/zap"
-	"io"
-	"mime/multipart"
-	"net/http"
-	"os"
-	"strings"
-	"time"
 )
 
 var ExcelServiceUrl = `http://47.105.103.181:4000/excel` // 新版解析excel服务
@@ -53,29 +53,27 @@ func HandleError(ctx context.Context, err error) error {
 		return nil
 	}
 	uuid := ""
-	_ = rod.Try(func() {
-		if ctx != nil {
-			uuid = ctx.Value(variable.UUID).(string)
-		}
-	})
+	if ctx != nil {
+		uuid, _ = ctx.Value(variable.UUID).(string)
+	}
 	var usererr *taxerr.UserErr
 	var taxerr2 *taxerr.SystemErr
 	if errors.As(err, &taxerr2) {
-		logger.Info(uuid, " ", taxerr2.Error())
+		logger.Info(uuid, taxerr2)
 		if !strings.Contains(taxerr2.Error(), "[异常]:") {
 			return errors.New("[异常]:" + taxerr2.Error())
 		} else {
 			return errors.New(taxerr2.Error())
 		}
 	} else if errors.As(err, &usererr) {
-		logger.Info(uuid, " ", usererr.Error())
+		logger.Info(uuid, usererr)
 		if !strings.Contains(usererr.Error(), "[错误]:") {
 			return errors.New("[错误]:" + usererr.Error())
 		} else {
 			return errors.New(usererr.Error())
 		}
 	} else if err != nil {
-		log.Error(uuid, " ", err.Error())
+		log.Error(uuid, err)
 		return taxerr.NewWebStuckTitle(true)
 	}
 	return nil
@@ -114,26 +112,26 @@ func HandleErrorBank(ctx context.Context, err error) error {
 	}
 	uuid := GetUUid()
 	if ctx != nil {
-		uuid = ctx.Value(variable.UUID).(string)
+		uuid, _ = ctx.Value(variable.UUID).(string)
 	}
 	var usererr *taxerr.UserErr
 	var taxerr *taxerr.SystemErr
 	if errors.As(err, &taxerr) {
-		logger.Info(uuid, " ", taxerr.Error())
+		logger.Info(uuid, taxerr)
 		if !strings.Contains(taxerr.Error(), "[异常]:") {
 			return errors.New("[异常]:" + taxerr.Error())
 		} else {
 			return errors.New(taxerr.Error())
 		}
 	} else if errors.As(err, &usererr) {
-		logger.Info(uuid, " ", usererr.Error())
+		logger.Info(uuid, usererr)
 		if !strings.Contains(usererr.Error(), "[错误]:") {
 			return errors.New("[错误]:" + usererr.Error())
 		} else {
 			return errors.New(usererr.Error())
 		}
 	} else if err != nil {
-		logger.Error(uuid, " ", err.Error())
+		logger.Error(uuid, err)
 		return BankStuckTitle()
 	}
 	return nil