-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
10 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,21 @@ | ||
package state | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk_errors "github.com/cosmos/cosmos-sdk/types/errors" | ||
sdk_abci "github.com/tendermint/tendermint/abci/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func sdkErrorToGRPCError(resp sdk_abci.ResponseQuery) error { | ||
switch codeToError(resp.Code) { | ||
case sdk_errors.ErrInvalidRequest: | ||
switch resp.Code { | ||
case sdk_errors.ErrInvalidRequest.ABCICode(): | ||
return status.Error(codes.InvalidArgument, resp.Log) | ||
case sdk_errors.ErrUnauthorized: | ||
case sdk_errors.ErrUnauthorized.ABCICode(): | ||
return status.Error(codes.Unauthenticated, resp.Log) | ||
case sdk_errors.ErrKeyNotFound: | ||
case sdk_errors.ErrKeyNotFound.ABCICode(): | ||
return status.Error(codes.NotFound, resp.Log) | ||
default: | ||
return status.Error(codes.Unknown, resp.Log) | ||
} | ||
} | ||
|
||
func codeToError(code uint32) error { | ||
switch code { | ||
case 0: | ||
return nil | ||
case sdk_errors.ErrTxDecode.ABCICode(): | ||
return sdk_errors.ErrTxDecode | ||
case sdk_errors.ErrUnauthorized.ABCICode(): | ||
return sdk_errors.ErrUnauthorized | ||
case sdk_errors.ErrInsufficientFunds.ABCICode(): | ||
return sdk_errors.ErrInsufficientFunds | ||
case sdk_errors.ErrInvalidAddress.ABCICode(): | ||
return sdk_errors.ErrInvalidAddress | ||
case sdk_errors.ErrUnknownAddress.ABCICode(): | ||
return sdk_errors.ErrUnknownAddress | ||
case sdk_errors.ErrInvalidCoins.ABCICode(): | ||
return sdk_errors.ErrInvalidCoins | ||
case sdk_errors.ErrOutOfGas.ABCICode(): | ||
return sdk_errors.ErrOutOfGas | ||
case sdk_errors.ErrInsufficientFee.ABCICode(): | ||
return sdk_errors.ErrInsufficientFee | ||
case sdk_errors.ErrJSONMarshal.ABCICode(): | ||
return sdk_errors.ErrJSONMarshal | ||
case sdk_errors.ErrJSONUnmarshal.ABCICode(): | ||
return sdk_errors.ErrJSONUnmarshal | ||
case sdk_errors.ErrTxTooLarge.ABCICode(): | ||
return sdk_errors.ErrTxTooLarge | ||
case sdk_errors.ErrorInvalidGasAdjustment.ABCICode(): | ||
return sdk_errors.ErrorInvalidGasAdjustment | ||
case sdk_errors.ErrLogic.ABCICode(): | ||
return sdk_errors.ErrLogic | ||
case sdk_errors.ErrNotFound.ABCICode(): | ||
return sdk_errors.ErrNotFound | ||
case sdk_errors.ErrIO.ABCICode(): | ||
return sdk_errors.ErrIO | ||
case sdk_errors.ErrInvalidGasLimit.ABCICode(): | ||
return sdk_errors.ErrInvalidGasLimit | ||
default: | ||
return fmt.Errorf("unknown error code received: %d", code) | ||
} | ||
} |