0
package main

import (
    "log"

    "github.com/stellar/go/clients/horizonclient"
    "github.com/stellar/go/keypair"
)

//unfunded seed on testnet
var stellar_seed = "SANIUNNZFTU7LNMYXMWL25SAYEQE7GI2JLBG2DMSMA3DLNEBOPH7HAMI"

func main() {
    // Make a keypair for a known account from a secret seed
    kp, _ := keypair.Parse(stellar_seed)

    // Get the current state of the account from the network
    client := horizonclient.DefaultTestNetClient
    ar := horizonclient.AccountRequest{AccountID: kp.Address()}
    sourceAccount, err := client.AccountDetail(ar)
    if err != nil {
        // log.Println(horizon.Error.Problem)
        log.Fatalln(err)
    }
    log.Println(sourceAccount)
}

Running this, I get the message:

2022/02/25 23:41:29 horizon error: "Resource Missing" - check horizon.Error.Problem for more information
exit status 1

How do I "check horizon.Error.Problem"?

1 Answer 1

1

"george" from the "Stellar Developers" discord #horizon chat answered me:

you can use the horizonclient.GetError(err) helper to retrieve the Problem structure and inspect it. For example,

if err != nil {
    log.Println(err)
    if p := horizonclient.GetError(err); p != nil {
        fmt.Printf("  Info: %s\n", p.Problem)
        if results, ok := p.Problem.Extras["result_codes"]; ok {
            fmt.Printf("  Extras: %s\n", results)
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.