diff --git a/servlet/rpc-servlet.go b/servlet/rpc-servlet.go index 8602087..31cbdda 100644 --- a/servlet/rpc-servlet.go +++ b/servlet/rpc-servlet.go @@ -72,12 +72,18 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx, params, err = src.Params() if nil != err { logging.Logger().Errore(err) + s.writeError(crp.E_BAD_PARAMS, "", err) break } grpcCtx = context.Background() - grpcReply, err = ogeg.Exec(grpcCTX, m, p...) + grpcReply, err = ogeg.Exec(grpcCtx, method, params...) replyBuff, err = src.NewResponseWithString(grpcReply, err) + if nil != err { + logging.Logger().Errore(err) + s.writeError(crp.E_INTERNAL, "", err) + break + } writeChan <- replyBuff case <-stopChan: @@ -87,3 +93,22 @@ func (s *RPCServlets) Handle(servletCtx server.ServletCtx, } } + +func (s *RPCServlets) writeError(src crp.ServerRequestCodec, writeChan chan<- []byte, code int, message string, data interface{}) { + if !src.HasResponse() { + return + } + + pErr := &crp.Error{ + Code: code, + Message: message, + Data: data, + } + + buf, err := src.NewResponse(nil, pErr) + if nil != err { + logging.Logger().Errore(err) + return + } + writeChan <- buf +}