Skip to content

Commit

Permalink
better error handling for some rpc methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tok-kkk committed Dec 1, 2021
1 parent 12ccecd commit 6db901d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/renproject/pack"
)

var ErrNotFound = sql.ErrNoRows

type TxStatus uint8

const (
Expand Down
12 changes: 11 additions & 1 deletion resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,13 @@ func (resolver *Resolver) SubmitGateway(ctx context.Context, id interface{}, par
func (resolver *Resolver) QueryGateway(ctx context.Context, id interface{}, params *ParamsQueryGateway, req *http.Request) jsonrpc.Response {
gateway, err := resolver.db.Gateway(params.Gateway)
if err != nil {
if err == sql.ErrNoRows {
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeResultNotFound, "not found", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}

resolver.logger.Errorf("[responder] cannot get gateway for gatewayAddress: %v :%v", params.Gateway, err)
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to query txid", nil)
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to query gateway", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}

Expand All @@ -325,6 +330,11 @@ func (resolver *Resolver) QueryGateway(ctx context.Context, id interface{}, para
func (resolver *Resolver) QueryTxByTxid(ctx context.Context, id interface{}, params *ParamsQueryTxByTxid, req *http.Request) jsonrpc.Response {
txs, err := resolver.db.TxsByTxid(params.Txid)
if err != nil {
if err == sql.ErrNoRows {
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeResultNotFound, "not found", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
}

resolver.logger.Errorf("[responder] cannot get txs for txid: %v :%v", params.Txid, err)
jsonErr := jsonrpc.NewError(jsonrpc.ErrorCodeInternal, "failed to query txid", nil)
return jsonrpc.NewResponse(id, nil, &jsonErr)
Expand Down

0 comments on commit 6db901d

Please sign in to comment.