diff --git a/main.go b/main.go index 93ec6fc..76cb7ca 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,7 @@ func main() { } var lastProposalId string + firstIteration := true for { latestProposal, err := getLatestProposal(cosmosEndpoint) if err != nil { @@ -63,15 +64,17 @@ func main() { } // post to slack only if didn't posted before - if lastProposalId != latestProposal.ID { + if !firstIteration && lastProposalId != latestProposal.ID { err = postToSlack(chainID, *latestProposal, slackWebhookURL) if err != nil { log.Errorf("Error posting to slack: %s\n", err) continue } - lastProposalId = latestProposal.ID } + lastProposalId = latestProposal.ID + firstIteration = false + time.Sleep(interval) } } diff --git a/proposals.go b/proposals.go index ccae820..3864a0a 100644 --- a/proposals.go +++ b/proposals.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "io" "net/http" ) @@ -64,5 +65,8 @@ func getLatestProposal(cosmosEndpoint string) (*Proposal, error) { if err != nil { return nil, err } + if len(proposalsData.Proposals) == 0 { + return nil, fmt.Errorf("no proposals found") + } return &proposalsData.Proposals[0], nil }