Algod client healtcheck method returns error although server returns 200
polarbit opened this issue · comments
Algod client's healtcheck method returns "json: Unmarshal(nil)" error ; although algod node returns success 200 (null).
The problem is: sdk tries to unmarshal node's healthcheck response; but the node returns http status 200 with "null" text content.
It can be fixed by unmarshaling the response only if provided response parameter is not null, at line 185 at file common.go
Your environment
go version: go1.17.6 darwin/amd64
algorand sdk: github.com/algorand/go-algorand-sdk v1.12.0
curl --location --request GET 'https://testnet-algorand.api.purestake.io/ps2/health' --header 'x-api-key: ***'
# Returns Status 200 (OK) with content "null"
Acceptance Criteria
- Review the go code, the go v1 SDK and the other SDKs.
- Avoid returning an error when there is no error.
This seems to work OK on v2.0.0:
// Create an algod client
algodClient, err := algod.MakeClient(algodAddress, algodToken)
if err != nil {
fmt.Printf("failed to make algod client: %s\n", err)
return
}
err := algodClient.HealthCheck().Do(context.Background())
fmt.Printf("algod health: %v\n", err)
returns: algod health: <nil>