added rpc error data

This commit is contained in:
Matt Johnstone 2024-10-14 17:20:34 +02:00
parent b2cde35375
commit 5ea95f245f
No known key found for this signature in database
GPG Key ID: BE985FBB9BE7D3BB
2 changed files with 5 additions and 4 deletions

View File

@ -131,7 +131,7 @@ func getResponse[T any](
return fmt.Errorf("failed to decode %s response body: %w", method, err) 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 { if rpcResponse.Error.Code != 0 {
return &rpcResponse.Error return &rpcResponse.Error
} }

View File

@ -7,8 +7,9 @@ import (
type ( type (
RPCError struct { RPCError struct {
Message string `json:"message"` Message string `json:"message"`
Code int64 `json:"code"` Code int64 `json:"code"`
Data map[string]any `json:"data"`
} }
response[T any] struct { response[T any] struct {
@ -97,7 +98,7 @@ type (
) )
func (e *RPCError) Error() string { 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 { func (hp *HostProduction) UnmarshalJSON(data []byte) error {