mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-01 15:18:59 +08:00
1
This commit is contained in:
parent
6c0175540b
commit
4f2d9c548e
@ -1260,6 +1260,7 @@ func GetGroupAbstractInfo(c *gin.Context) {
|
|||||||
req api.GetGroupAbstractInfoReq
|
req api.GetGroupAbstractInfoReq
|
||||||
resp api.GetGroupAbstractInfoResp
|
resp api.GetGroupAbstractInfoResp
|
||||||
)
|
)
|
||||||
|
nCtx := trace_log.NewCtx(c, utils.GetSelfFuncName())
|
||||||
if err := c.BindJSON(&req); err != nil {
|
if err := c.BindJSON(&req); err != nil {
|
||||||
log.NewError("0", "BindJSON failed ", err.Error())
|
log.NewError("0", "BindJSON failed ", err.Error())
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
@ -1289,8 +1290,9 @@ func GetGroupAbstractInfo(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", respPb.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", respPb.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", err.Error())
|
//log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", err.Error())
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
//c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||||
|
trace_log.WriteErrorResponse(nCtx, "GetGroupAbstractInfo", utils.Wrap(err, ""))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||||
|
@ -4,7 +4,10 @@ import (
|
|||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"google.golang.org/grpc/status"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
//"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -51,17 +54,55 @@ func ShowLog(ctx context.Context) {
|
|||||||
|
|
||||||
func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||||
SetContextInfo(ctx, funcName, err, args)
|
SetContextInfo(ctx, funcName, err, args)
|
||||||
e := new(constant.ErrInfo)
|
e := Unwrap(err)
|
||||||
switch {
|
switch t := e.(type) {
|
||||||
case errors.As(err, &e):
|
case *constant.ErrInfo:
|
||||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": e.ErrCode, "errMsg": e.ErrMsg})
|
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg})
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": constant.ErrDefaultOther.ErrMsg})
|
s, ok := status.FromError(err)
|
||||||
|
if !ok {
|
||||||
|
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var details []string
|
||||||
|
if err != e {
|
||||||
|
details = append(details, fmt.Sprintf("%+v", err))
|
||||||
|
}
|
||||||
|
for _, s := range s.Details() {
|
||||||
|
details = append(details, fmt.Sprintf("%+v", s))
|
||||||
|
}
|
||||||
|
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.String(), "errDtl": strings.Join(details, "\n")})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||||
|
// SetContextInfo(ctx, funcName, err, args)
|
||||||
|
// e := new(constant.ErrInfo)
|
||||||
|
// switch {
|
||||||
|
// case errors.As(err, &e):
|
||||||
|
// ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": e.ErrCode, "errMsg": e.ErrMsg})
|
||||||
|
// return
|
||||||
|
// default:
|
||||||
|
// ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": constant.ErrDefaultOther.ErrMsg, "errDtl": err.Error()})
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
func Unwrap(err error) error {
|
||||||
|
for err != nil {
|
||||||
|
unwrap, ok := err.(interface {
|
||||||
|
Unwrap() error
|
||||||
|
})
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
err = unwrap.Unwrap()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type ApiInfo struct {
|
type ApiInfo struct {
|
||||||
ApiName string
|
ApiName string
|
||||||
OperationID string
|
OperationID string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user