From 15e453fe85cd687d7cdb0f5d5a89facef1e5f586 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 25 Jan 2022 10:06:37 +0100 Subject: [PATCH] fix: return 404 on non-existing tx (backport #10992) (#11014) * fix: return 404 on non-existing tx (#10992) (cherry picked from commit 158128953c45f95fb4fd7ed737005b2bd9c9f1eb) # Conflicts: # CHANGELOG.md * fix cl Co-authored-by: Aleksandr Bezobchuk Co-authored-by: Aleksandr Bezobchuk --- CHANGELOG.md | 4 ++++ x/auth/tx/service.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbebe05b561a1..0ec7792365c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Bug Fixes + +* (grpc) [\#10985](https://github.com/cosmos/cosmos-sdk/pull/10992) The `/cosmos/tx/v1beta1/txs/{hash}` endpoint returns a 404 when a tx does not exist. + ## [v0.45.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.0) - 2022-01-18 ### State Machine Breaking diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index a0deedae6aa24..00f123c571121 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -131,10 +131,18 @@ func (s txServer) GetTx(ctx context.Context, req *txtypes.GetTxRequest) (*txtype return nil, status.Error(codes.InvalidArgument, "request cannot be nil") } + if len(req.Hash) == 0 { + return nil, status.Error(codes.InvalidArgument, "tx hash cannot be empty") + } + // TODO We should also check the proof flag in gRPC header. // https://github.com/cosmos/cosmos-sdk/issues/7036. result, err := QueryTx(s.clientCtx, req.Hash) if err != nil { + if strings.Contains(err.Error(), "not found") { + return nil, status.Errorf(codes.NotFound, "tx not found: %s", req.Hash) + } + return nil, err }