Skip to content

Commit

Permalink
fix(SPV-846): handle exeptions example
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain committed Jul 4, 2024
1 parent ae50a5c commit c42d4bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions examples/handle_exceptions/handle_exceptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package main

import (
"context"
"errors"
"fmt"
"os"

walletclient "github.com/bitcoin-sv/spv-wallet-go-client"
"github.com/bitcoin-sv/spv-wallet-go-client/examples"
"github.com/bitcoin-sv/spv-wallet/models"
)

func main() {
Expand All @@ -24,8 +26,12 @@ func main() {

status, err := client.AdminGetStatus(ctx)
if err != nil {
fmt.Println("Response status: ", err.GetStatusCode())
fmt.Println("Content: ", err.Error())
var extendedErr models.ExtendedError
if errors.As(err, &extendedErr) {
fmt.Printf("Extended error: [%d] '%s': %s\n", extendedErr.GetStatusCode(), extendedErr.GetCode(), extendedErr.GetMessage())
} else {
fmt.Println("Error: ", err.Error())
}

os.Exit(1)
}
Expand Down
5 changes: 4 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/bitcoinschema/go-bitcoin/v2"
"net/http"
"strconv"

"github.com/bitcoin-sv/spv-wallet-go-client/utils"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bk/bec"
"github.com/libsv/go-bk/bip32"
)
Expand Down Expand Up @@ -565,6 +565,9 @@ func (wc *WalletClient) authenticateWithXpriv(sign bool, req *http.Request, xPri
}

func (wc *WalletClient) authenticateWithAccessKey(req *http.Request, rawJSON []byte) error {
if wc.accessKey == nil {
return WrapError(errors.New("access key is missing"))
}
return SetSignatureFromAccessKey(&req.Header, hex.EncodeToString(wc.accessKey.Serialise()), string(rawJSON))
}

Expand Down

0 comments on commit c42d4bb

Please sign in to comment.