Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error messages for legacy rest endpoints #7856

Merged
merged 14 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions x/auth/client/rest/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strings"

"github.com/cosmos/cosmos-sdk/client"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -55,6 +56,17 @@ func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {

response := DecodeResp(stdTx)

_, err = clientCtx.LegacyAmino.MarshalJSON(response)
if err != nil {
if strings.Contains(err.Error(), "unregistered concrete type") {
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
rest.WriteErrorResponse(w, http.StatusInternalServerError,
"This transaction was created with the new SIGN_MODE_DIRECT signing method, and therefore cannot be displayed"+
" via legacy REST handlers, please use CLI or directly query the Tendermint RPC endpoint to query"+
" this transaction. gRPC gateway endpoint is /cosmos/tx/v1beta1/txs/decode")
}
return
}

rest.PostProcessResponse(w, clientCtx, response)
}
}
Expand Down
22 changes: 22 additions & 0 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
packStdTxResponse(w, clientCtx, txRes)
}

_, err = clientCtx.LegacyAmino.MarshalJSON(searchResult)
if err != nil {
if strings.Contains(err.Error(), "unregistered concrete type") {
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
rest.WriteErrorResponse(w, http.StatusInternalServerError,
"This transaction was created with the new SIGN_MODE_DIRECT signing method, and therefore cannot be displayed"+
" via legacy REST handlers, please use CLI or directly query the Tendermint RPC endpoint to query"+
" this transaction. gRPC gateway endpoint is /cosmos/tx/v1beta1/txs")
}
return
}

rest.PostProcessResponseBare(w, clientCtx, searchResult)
}
}
Expand Down Expand Up @@ -143,6 +154,17 @@ func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
rest.WriteErrorResponse(w, http.StatusNotFound, fmt.Sprintf("no transaction found with hash %s", hashHexStr))
}

_, err = clientCtx.LegacyAmino.MarshalJSON(output)
if err != nil {
if strings.Contains(err.Error(), "unregistered concrete type") {
rest.WriteErrorResponse(w, http.StatusInternalServerError,
"This transaction was created with the new SIGN_MODE_DIRECT signing method, and therefore cannot be displayed"+
" via legacy REST handlers, please use CLI or directly query the Tendermint RPC endpoint to query"+
" this transaction. gRPC gateway endpoint is /cosmos/tx/v1beta1/tx/<txhash>")
}
return
}

rest.PostProcessResponseBare(w, clientCtx, output)
}
}
Expand Down