Skip to content

Commit

Permalink
feat: add logs and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed May 10, 2022
1 parent 050d32c commit ea9d97e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions graph/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,44 @@ import (

"okp4/cosmos-faucet/graph/generated"
"okp4/cosmos-faucet/graph/model"

"github.com/99designs/gqlgen/graphql"
"github.com/rs/zerolog/log"
)

func (r *mutationResolver) Send(ctx context.Context, input model.SendInput) (*model.TxResponse, error) {
resp, err := r.Faucet.SendTxMsg(ctx, input.ToAddress)

if err != nil {
log.Err(err).Msg("Transaction failed.")
return nil, err
}

return &model.TxResponse{
log.Info().
Str("toAddress", input.ToAddress).
Str("fromAddress", r.Faucet.FromAddr.String()).
Msgf("Send %d%s to %s...", r.Faucet.Config.AmountSend, r.Faucet.Config.Denom, input.ToAddress)

response := &model.TxResponse{
Hash: resp.TxHash,
Code: int(resp.Code),
RawLog: &resp.RawLog,
GasWanted: resp.GasWanted,
GasUsed: resp.GasUsed,
}, nil
}

log.Debug().
Interface("response", response).
Msg("Transaction has been broadcast")

if resp.Code != 0 {
graphql.AddErrorf(ctx, "transaction is not successful: %s (code: %d)", resp.RawLog, resp.Code)
log.Error().Str("log", resp.RawLog).
Uint32("code", resp.Code).
Msgf("transaction is not successful")
}

return response, nil
}

func (r *queryResolver) Health(ctx context.Context) (*string, error) {
Expand Down

0 comments on commit ea9d97e

Please sign in to comment.