From 70d384c757fd8b1b21f2ef81a589f951dcf0c05b Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Fri, 12 Jan 2024 18:40:21 -0500 Subject: [PATCH] check transaction was found --- api/server.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/server.go b/api/server.go index 7619f607..b495e6d7 100644 --- a/api/server.go +++ b/api/server.go @@ -1,6 +1,7 @@ package api import ( + "errors" "fmt" "net/http" @@ -164,6 +165,8 @@ func (s *server) explorerBlockHeightHandler(jc jape.Context) { } func (s *server) explorerTransactionsIDHandler(jc jape.Context) { + errNotFound := errors.New("no transaction found") + var id types.TransactionID if jc.DecodeParam("id", &id) != nil { return @@ -171,6 +174,9 @@ func (s *server) explorerTransactionsIDHandler(jc jape.Context) { txns, err := s.e.Transactions([]types.TransactionID{id}) if jc.Check("failed to get transaction", err) != nil { return + } else if len(txns) == 0 { + jc.Error(errNotFound, http.StatusNotFound) + return } jc.Encode(txns[0]) }