mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-03 11:45:18 +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:
@@ -80,12 +80,12 @@ func TestProvider(t *testing.T) {
|
||||
lb, err = p.LightBlock(ctx, 9001)
|
||||
require.Error(t, err)
|
||||
require.Nil(t, lb)
|
||||
assert.Equal(t, provider.ErrHeightTooHigh, err)
|
||||
assert.ErrorIs(t, err, provider.ErrHeightTooHigh)
|
||||
|
||||
lb, err = p.LightBlock(ctx, 1)
|
||||
require.Error(t, err)
|
||||
require.Nil(t, lb)
|
||||
assert.Equal(t, provider.ErrLightBlockNotFound, err)
|
||||
assert.ErrorIs(t, err, provider.ErrLightBlockNotFound)
|
||||
|
||||
// if the provider is unable to provide four more blocks then we should return
|
||||
// an unreliable peer error
|
||||
|
||||
@@ -655,11 +655,7 @@ func (c *Client) SubscribeWS(ctx context.Context, query string) (*coretypes.Resu
|
||||
case resultEvent := <-out:
|
||||
// We should have a switch here that performs a validation
|
||||
// depending on the event's type.
|
||||
callInfo.WSConn.TryWriteRPCResponse(bctx,
|
||||
rpctypes.NewRPCSuccessResponse(
|
||||
rpctypes.JSONRPCStringID(fmt.Sprintf("%v#event", callInfo.RPCRequest.ID)),
|
||||
resultEvent,
|
||||
))
|
||||
callInfo.WSConn.TryWriteRPCResponse(bctx, callInfo.RPCRequest.MakeResponse(resultEvent))
|
||||
case <-bctx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user