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 <neeraj.rtly@gmail.com>
Reviewed-on: deep-stack/laconic2d#20
Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
This commit is contained in:
Prathamesh Musale 2024-03-12 08:40:23 +00:00 committed by nabarun
parent 67cbbf7088
commit 373af7562b

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"strconv" "strconv"
"strings"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types"
@ -41,6 +42,11 @@ func (q queryResolver) LookupAuthorities(ctx context.Context, names []string) ([
for _, name := range names { for _, name := range names {
res, err := nsQueryClient.Whois(context.Background(), &registrytypes.QueryWhoisRequest{Name: name}) res, err := nsQueryClient.Whois(context.Background(), &registrytypes.QueryWhoisRequest{Name: name})
if err != nil { if err != nil {
if strings.Contains(err.Error(), "Name authority not found") {
gqlResponse = append(gqlResponse, nil)
continue
}
return nil, err return nil, err
} }
@ -263,6 +269,10 @@ func (q *queryResolver) GetBond(ctx context.Context, id string) (*Bond, error) {
bondQueryClient := bondtypes.NewQueryClient(q.ctx) bondQueryClient := bondtypes.NewQueryClient(q.ctx)
bondResp, err := bondQueryClient.GetBondById(context.Background(), &bondtypes.QueryGetBondByIdRequest{Id: id}) bondResp, err := bondQueryClient.GetBondById(context.Background(), &bondtypes.QueryGetBondByIdRequest{Id: id})
if err != nil { if err != nil {
if strings.Contains(err.Error(), "Bond not found") {
return nil, nil
}
return nil, err return nil, err
} }