diff --git a/x/proof/keeper/session.go b/x/proof/keeper/session.go index 9d33d76c6..68a72cf10 100644 --- a/x/proof/keeper/session.go +++ b/x/proof/keeper/session.go @@ -2,8 +2,10 @@ package keeper import ( "context" + "fmt" cosmostypes "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" @@ -30,6 +32,8 @@ func (k Keeper) queryAndValidateSessionHeader( // session header is to be validated. sessionRes, err := k.sessionKeeper.GetSession(ctx, sessionReq) if err != nil { + // NB: Strip internal error status from error. An appropriate status will be associated by the caller. + err = fmt.Errorf("%s", status.Convert(err).Message()) return nil, err } onChainSession := sessionRes.GetSession() diff --git a/x/session/keeper/msg_update_params.go b/x/session/keeper/msg_update_params.go index 84a5debfa..57564b921 100644 --- a/x/session/keeper/msg_update_params.go +++ b/x/session/keeper/msg_update_params.go @@ -2,21 +2,34 @@ package keeper import ( "context" + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/x/session/types" ) func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + logger := k.Logger().With("method", "UpdateParams") + if err := req.ValidateBasic(); err != nil { - return nil, err + return nil, status.Error(codes.InvalidArgument, err.Error()) } if k.GetAuthority() != req.Authority { - return nil, types.ErrSessionInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + return nil, status.Error( + codes.PermissionDenied, + types.ErrSessionInvalidSigner.Wrapf( + "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority, + ).Error(), + ) } if err := k.SetParams(ctx, req.Params); err != nil { - return nil, err + err = fmt.Errorf("unable to set params: %w", err) + logger.Error(err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } return &types.MsgUpdateParamsResponse{}, nil diff --git a/x/session/keeper/query_get_session.go b/x/session/keeper/query_get_session.go index bc25fff0e..412d77c45 100644 --- a/x/session/keeper/query_get_session.go +++ b/x/session/keeper/query_get_session.go @@ -14,6 +14,8 @@ import ( // GetSession should be deterministic and always return the same session for // the same block height. func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionRequest) (*types.QueryGetSessionResponse, error) { + logger := k.Logger().With("method", "GetSession") + if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -36,12 +38,13 @@ func (k Keeper) GetSession(ctx context.Context, req *types.QueryGetSessionReques blockHeight = req.BlockHeight } - k.Logger().Debug(fmt.Sprintf("Getting session for height: %d", blockHeight)) + logger.Debug(fmt.Sprintf("Getting session for height: %d", blockHeight)) sessionHydrator := NewSessionHydrator(req.ApplicationAddress, req.ServiceId, blockHeight) session, err := k.HydrateSession(ctx, sessionHydrator) if err != nil { - return nil, err + logger.Error(err.Error()) + return nil, status.Error(codes.Internal, err.Error()) } res := &types.QueryGetSessionResponse{