Skip to content

Commit

Permalink
chore: returning errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanCapistrano committed Sep 17, 2023
1 parent 1a46a33 commit 7d81ef0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions info/getNodeInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package info

import (
"context"
"log"
"errors"

iotago "github.com/iotaledger/iota.go/v2"
)
Expand All @@ -23,12 +23,12 @@ type Milestone struct {
}

// Get Tangle Hornet Network node information.
func GetNodeInfo(nodeUrl string) NodeInfo {
func GetNodeInfo(nodeUrl string) (NodeInfo, error) {
node := iotago.NewNodeHTTPAPIClient(nodeUrl)

info, err := node.Info(context.Background())
if err != nil {
log.Fatal("Unable to get node information.")
return NodeInfo{}, errors.New("unable to get node information")
}

milestone := &Milestone{
Expand All @@ -37,12 +37,14 @@ func GetNodeInfo(nodeUrl string) NodeInfo {
LatestMilestoneTimestamp: info.LatestMilestoneTimestamp,
}

return NodeInfo{
nodeInfo := &NodeInfo{
Name: info.Name,
NetworkId: info.NetworkID,
Version: info.Version,
MessagesPerSecond: info.MessagesPerSecond,
Milestone: *milestone,
IsHealthy: info.IsHealthy,
}

return *nodeInfo, nil
}

0 comments on commit 7d81ef0

Please sign in to comment.