Skip to content

Commit

Permalink
Replace err == ... with errors.Is(err, ...) (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan authored Jan 17, 2025
1 parent d21713e commit fab471c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/db/last_processed_height.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package db
import (
"context"

"errors"
"github.com/babylonlabs-io/babylon-staking-indexer/internal/db/model"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand All @@ -13,11 +14,11 @@ func (db *Database) GetLastProcessedBbnHeight(ctx context.Context) (uint64, erro
var result model.LastProcessedHeight
err := db.collection(model.LastProcessedHeightCollection).
FindOne(ctx, bson.M{}).Decode(&result)
if err == mongo.ErrNoDocuments {
// If no document exists, return 0
return 0, nil
}
if err != nil {
if errors.Is(err, mongo.ErrNoDocuments) {
// If no document exists, return 0
return 0, nil
}
return 0, err
}
return result.Height, nil
Expand Down

0 comments on commit fab471c

Please sign in to comment.