mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-09-01 12:10:04 +08:00
1
This commit is contained in:
parent
03dd50e25c
commit
16864dab7d
@ -70,12 +70,14 @@ func WriteErrorResponse(ctx context.Context, funcName string, err error, args ..
|
|||||||
e := Unwrap(err)
|
e := Unwrap(err)
|
||||||
switch t := e.(type) {
|
switch t := e.(type) {
|
||||||
case *constant.ErrInfo:
|
case *constant.ErrInfo:
|
||||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg})
|
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, baseResp{ErrCode: t.ErrCode, ErrMsg: t.ErrMsg, ErrDtl: t.DetailErrMsg})
|
||||||
|
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg})
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
s, ok := status.FromError(e)
|
s, ok := status.FromError(e)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)})
|
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: constant.ErrDefaultOther.ErrCode, ErrMsg: err.Error(), ErrDtl: fmt.Sprintf("%+v", err)})
|
||||||
|
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var details []string
|
var details []string
|
||||||
@ -85,11 +87,19 @@ func WriteErrorResponse(ctx context.Context, funcName string, err error, args ..
|
|||||||
for _, s := range s.Details() {
|
for _, s := range s.Details() {
|
||||||
details = append(details, fmt.Sprintf("%+v", s))
|
details = append(details, fmt.Sprintf("%+v", s))
|
||||||
}
|
}
|
||||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.Message(), "errDtl": strings.Join(details, "\n")})
|
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: int32(s.Code()), ErrMsg: s.Message(), ErrDtl: strings.Join(details, "\n")})
|
||||||
|
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.Message(), "errDtl": strings.Join(details, "\n")})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type baseResp struct {
|
||||||
|
ErrCode int32 `json:"errCode"`
|
||||||
|
ErrMsg string `json:"errMsg"`
|
||||||
|
ErrDtl string `json:"errDtl"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
//func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
//func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||||
// SetCtxInfo(ctx, funcName, err, args)
|
// SetCtxInfo(ctx, funcName, err, args)
|
||||||
// e := new(constant.ErrInfo)
|
// e := new(constant.ErrInfo)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user