summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchris erway <chris.erway@algorand.com>2022-02-24 09:34:33 -0500
committerchris erway <chris.erway@algorand.com>2022-02-24 09:34:41 -0500
commitb737a8f15ddc0b6f4d92598843fedca489e64ff9 (patch)
treef834c26fa516f8f035d6bce4939fc9af58205766
parent2ee1c5cdae9885536cc34d1937851ec905726045 (diff)
goal: handle not found for looking up AppLocalState with errorAcountNotOptedInToApp
-rw-r--r--cmd/goal/application.go7
-rw-r--r--cmd/goal/interact.go7
-rw-r--r--daemon/algod/api/client/restClient.go14
3 files changed, 27 insertions, 1 deletions
diff --git a/cmd/goal/application.go b/cmd/goal/application.go
index 6d1c1979d..9769e8cb5 100644
--- a/cmd/goal/application.go
+++ b/cmd/goal/application.go
@@ -23,7 +23,9 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/hex"
+ "errors"
"fmt"
+ "net/http"
"os"
"strconv"
"strings"
@@ -31,6 +33,7 @@ import (
"github.com/spf13/cobra"
"github.com/algorand/go-algorand/crypto"
+ apiclient "github.com/algorand/go-algorand/daemon/algod/api/client"
"github.com/algorand/go-algorand/data/abi"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
@@ -955,6 +958,10 @@ var readStateAppCmd = &cobra.Command{
// Fetching local state. Get account information
ai, err := client.RawAccountApplicationInformation(account, appIdx)
if err != nil {
+ var httpError apiclient.HTTPError
+ if errors.As(err, &httpError) && httpError.StatusCode == http.StatusNotFound {
+ reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
+ }
reportErrorf(errorRequestFail, err)
}
diff --git a/cmd/goal/interact.go b/cmd/goal/interact.go
index 0dabb2699..6b157a50d 100644
--- a/cmd/goal/interact.go
+++ b/cmd/goal/interact.go
@@ -20,7 +20,9 @@ import (
"encoding/base32"
"encoding/base64"
"encoding/json"
+ "errors"
"fmt"
+ "net/http"
"os"
"strconv"
"strings"
@@ -28,6 +30,7 @@ import (
"github.com/spf13/cobra"
"github.com/algorand/go-algorand/crypto"
+ apiclient "github.com/algorand/go-algorand/daemon/algod/api/client"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
@@ -673,6 +676,10 @@ var appQueryCmd = &cobra.Command{
// Fetching local state. Get account information
ai, err := client.RawAccountApplicationInformation(account, appIdx)
if err != nil {
+ var httpError apiclient.HTTPError
+ if errors.As(err, &httpError) && httpError.StatusCode == http.StatusNotFound {
+ reportErrorf(errorAccountNotOptedInToApp, account, appIdx)
+ }
reportErrorf(errorRequestFail, err)
}
diff --git a/daemon/algod/api/client/restClient.go b/daemon/algod/api/client/restClient.go
index e9852e7aa..7f8b2d412 100644
--- a/daemon/algod/api/client/restClient.go
+++ b/daemon/algod/api/client/restClient.go
@@ -78,6 +78,18 @@ func (e unauthorizedRequestError) Error() string {
return fmt.Sprintf("Unauthorized request to `%s` when using token `%s` : %s", e.url, e.apiToken, e.errorString)
}
+// HTTPError is generated when we receive an unhandled error from the server. This error contains the error string.
+type HTTPError struct {
+ StatusCode int
+ Status string
+ ErrorString string
+}
+
+// Error formats an error string.
+func (e HTTPError) Error() string {
+ return fmt.Sprintf("HTTP %s: %s", e.Status, e.ErrorString)
+}
+
// RestClient manages the REST interface for a calling user.
type RestClient struct {
serverURL url.URL
@@ -131,7 +143,7 @@ func extractError(resp *http.Response) error {
return unauthorizedRequestError{errorString, apiToken, resp.Request.URL.String()}
}
- return fmt.Errorf("HTTP %s: %s", resp.Status, errorString)
+ return HTTPError{StatusCode: resp.StatusCode, Status: resp.Status, ErrorString: errorString}
}
// stripTransaction gets a transaction of the form "tx-XXXXXXXX" and truncates the "tx-" part, if it starts with "tx-"