错误监听

This commit is contained in:
meixiongfeng 2023-01-14 22:07:27 +08:00
parent 64980cb107
commit 2f26e7ab3d

View File

@ -8,6 +8,7 @@ import (
"go_dreamfactory/sys/configure"
"go_dreamfactory/sys/db"
"reflect"
"runtime"
"sync"
"time"
@ -118,15 +119,15 @@ func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value,
//Rpc_GatewayRoute服务接口的接收函数
func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) (err error) {
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
// defer func() { //程序异常 收集异常信息传递给前端显示
// if r := recover(); r != nil {
// buf := make([]byte, 4096)
// l := runtime.Stack(buf, false)
// reply.Code = pb.ErrorCode_Exception
// reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
// log.Errorf("[Handle Api] m:%s reply:%s", method, reply)
// }
// }()
defer func() { //程序异常 收集异常信息传递给前端显示
if r := recover(); r != nil {
buf := make([]byte, 4096)
l := runtime.Stack(buf, false)
reply.Code = pb.ErrorCode_Exception
reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
log.Errorf("[Handle Api] m:%s reply:%s", method, reply)
}
}()
//获取用户消息处理函数
this.mrlock.RLock()
msghandle, ok := this.msghandles[method]