From 1d758f16e27af60da27ca1da3268a3545f5ce0a8 Mon Sep 17 00:00:00 2001 From: lixiangyang Date: Thu, 22 Aug 2024 11:05:07 +0800 Subject: [PATCH] feat: write an error message after you recover --- server/server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index bbccad3f..63f44784 100644 --- a/server/server.go +++ b/server/server.go @@ -534,8 +534,13 @@ func (s *Server) processOneRequest(ctx *share.Context, req *protocol.Message, co if r := recover(); r != nil { buf := make([]byte, 1024) buf = buf[:runtime.Stack(buf, true)] - - log.Errorf("failed to handle the request: %v, stacks: %s", r, buf) + if s.HandleServiceError != nil { + s.HandleServiceError(fmt.Errorf("%v", r)) + } else { + log.Errorf("[handler internal error]: servicepath: %s, servicemethod, err: %v,stacks: %s", req.ServicePath, req.ServiceMethod, r, buf) + } + sctx := NewContext(ctx, conn, req, s.AsyncWrite) + sctx.WriteError(fmt.Errorf("%v", r)) } }()