Skip to content

Commit 8c57974

Browse files
committed
fix(rpc - Go part): handle error responses from JSON-RPC
1 parent 4f12bcf commit 8c57974

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

goCode/internal/rpc/rpc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ func GetLatestBlock(rpcURL string) string {
4141
log.Fatalf("Greska pri parsiranju JSON odgovora: %v", err)
4242
}
4343

44+
if rpcResp.Error != nil {
45+
log.Fatalf(
46+
"RPC greska (code=%d): %s",
47+
rpcResp.Error.Code,
48+
rpcResp.Error.Message,
49+
)
50+
}
51+
4452
fmt.Println("sadrzaj BLOCK-a:\n", string(rpcResp.Result))
4553
fmt.Println()
4654

goCode/internal/rpc/types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ type RPCRequest struct {
99
ID int `json:"id"`
1010
}
1111

12+
type RPCError struct {
13+
Code int `json:"code"`
14+
Message string `json:"message"`
15+
}
16+
1217
type RPCResponse struct {
1318
Jsonrpc string `json:"jsonrpc"`
1419
ID int `json:"id"`
15-
Result json.RawMessage `json:"result"` // Sirovi JSON za parsiranje
20+
Result json.RawMessage `json:"result"`
21+
Error *RPCError `json:"error,omitempty"`
1622
}
1723

1824
type Block struct {

0 commit comments

Comments
 (0)