From 373af7562b4f6c3e41cfec70cc5b60c8c8b7f4a0 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 12 Mar 2024 08:40:23 +0000 Subject: [PATCH] Handle not found errors in GQL query resolvers (#20) Part of https://www.notion.so/Create-laconic-registry-SDK-d3a636d4aba44f7cbba3bd99b7146811 - Return `nil` in response when - bond not found on `getBondsByIds` request - authority not found on `lookupAuthorities` / `whois` request Co-authored-by: neeraj Reviewed-on: https://git.vdb.to/deep-stack/laconic2d/pulls/20 Co-authored-by: Prathamesh Musale Co-committed-by: Prathamesh Musale --- gql/resolver.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gql/resolver.go b/gql/resolver.go index 0c564b72..9dc3e9f1 100644 --- a/gql/resolver.go +++ b/gql/resolver.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "strconv" + "strings" "github.com/cosmos/cosmos-sdk/client" types "github.com/cosmos/cosmos-sdk/types" @@ -41,6 +42,11 @@ func (q queryResolver) LookupAuthorities(ctx context.Context, names []string) ([ for _, name := range names { res, err := nsQueryClient.Whois(context.Background(), ®istrytypes.QueryWhoisRequest{Name: name}) if err != nil { + if strings.Contains(err.Error(), "Name authority not found") { + gqlResponse = append(gqlResponse, nil) + continue + } + return nil, err } @@ -263,6 +269,10 @@ func (q *queryResolver) GetBond(ctx context.Context, id string) (*Bond, error) { bondQueryClient := bondtypes.NewQueryClient(q.ctx) bondResp, err := bondQueryClient.GetBondById(context.Background(), &bondtypes.QueryGetBondByIdRequest{Id: id}) if err != nil { + if strings.Contains(err.Error(), "Bond not found") { + return nil, nil + } + return nil, err }