Skip to content

Commit

Permalink
added rpc error data
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstonematt committed Oct 14, 2024
1 parent b2cde35 commit 5ea95f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func getResponse[T any](
return fmt.Errorf("failed to decode %s response body: %w", method, err)
}

// last error check:
// check for an actual rpc error
if rpcResponse.Error.Code != 0 {
return &rpcResponse.Error
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/rpc/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

type (
RPCError struct {
Message string `json:"message"`
Code int64 `json:"code"`
Message string `json:"message"`
Code int64 `json:"code"`
Data map[string]any `json:"data"`
}

response[T any] struct {
Expand Down Expand Up @@ -97,7 +98,7 @@ type (
)

func (e *RPCError) Error() string {
return fmt.Sprintf("RPC Error (%d): %s", e.Code, e.Message)
return fmt.Sprintf("rpc error (code: %d): %s (data: %v)", e.Code, e.Message, e.Data)
}

func (hp *HostProduction) UnmarshalJSON(data []byte) error {
Expand Down

0 comments on commit 5ea95f2

Please sign in to comment.