mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 22:44:24 +00:00
rpc: simplify and consolidate response construction (#7725)
Responses are constructed from requests using MakeResponse, MakeError, and MakeErrorf. This ensures the response is always paired with the correct ID, makes cases where there is no ID more explicit at the usage site, and consolidates the handling of error introspection across transports. The logic for unpacking errors and assigning JSON-RPC response types was previously duplicated in three places. Consolidate it in the types package for the RPC subsystem. * update test cases
This commit is contained in:
@@ -67,7 +67,7 @@ func (env *Environment) Subscribe(ctx context.Context, query string) (*coretypes
|
||||
return
|
||||
} else if errors.Is(err, tmpubsub.ErrTerminated) {
|
||||
// The subscription was terminated by the publisher.
|
||||
resp := rpctypes.RPCServerError(subscriptionID, err)
|
||||
resp := callInfo.RPCRequest.MakeError(err)
|
||||
ok := callInfo.WSConn.TryWriteRPCResponse(opctx, resp)
|
||||
if !ok {
|
||||
env.Logger.Info("Unable to write response (slow client)",
|
||||
@@ -77,7 +77,7 @@ func (env *Environment) Subscribe(ctx context.Context, query string) (*coretypes
|
||||
}
|
||||
|
||||
// We have a message to deliver to the client.
|
||||
resp := rpctypes.NewRPCSuccessResponse(subscriptionID, &coretypes.ResultEvent{
|
||||
resp := callInfo.RPCRequest.MakeResponse(&coretypes.ResultEvent{
|
||||
Query: query,
|
||||
Data: msg.Data(),
|
||||
Events: msg.Events(),
|
||||
|
||||
Reference in New Issue
Block a user