Skip to content

Commit

Permalink
more explictly handle 404 on GetProgressReport as not error (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
msf authored Jun 20, 2024
1 parent 42315d3 commit 82a4e91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions client/duneapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,22 @@ func (c *client) GetProgressReport(ctx context.Context) (*models.BlockchainIndex
return nil, err
}

if resp.StatusCode == http.StatusNotFound {
// no progress yet, first ingest for this chain
return &models.BlockchainIndexProgress{
BlockchainName: c.cfg.BlockchainName,
EVMStack: c.cfg.Stack.String(),
LastIngestedBlockNumber: -1, // no block ingested
LatestBlockNumber: 0,
}, nil
}
if resp.StatusCode != http.StatusOK {
var errorResp errorResponse
err = json.Unmarshal(responseBody, &errorResp)
if err != nil {
return nil, err
}
err = fmt.Errorf("got non-OK response, status code: %d, body: '%s'", resp.StatusCode, errorResp.Error)
// No progress yet
if resp.StatusCode == http.StatusNotFound {
return &models.BlockchainIndexProgress{
BlockchainName: c.cfg.BlockchainName,
EVMStack: c.cfg.Stack.String(),
LastIngestedBlockNumber: 0,
LatestBlockNumber: 0,
}, nil
}
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func main() {
progress, err := duneClient.GetProgressReport(ctx)
if err != nil {
stdlog.Fatal(err)
} else {
startBlockNumber = progress.LastIngestedBlockNumber + 1
}
startBlockNumber = progress.LastIngestedBlockNumber + 1
} else {
startBlockNumber = cfg.BlockHeight
}
Expand Down

0 comments on commit 82a4e91

Please sign in to comment.