Skip to content

Commit

Permalink
fix(repository): send logs to manager on read errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Jan 12, 2025
1 parent 5fe581a commit a0cf0ac
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions repository/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repository
import (
"context"

"github.com/dezh-tech/immortal/pkg/logger"
"github.com/dezh-tech/immortal/types"
"github.com/dezh-tech/immortal/types/event"
"github.com/dezh-tech/immortal/types/filter"
Expand Down Expand Up @@ -73,13 +74,27 @@ func (h *Handler) HandleReq(f *filter.Filter) ([]event.Event, error) {
collection := h.db.Client.Database(h.db.DBName).Collection("empty")
cursor, err := collection.Aggregate(ctx, pipeline)
if err != nil {
_, err := h.grpc.AddLog(context.Background(),
"database error while adding new event", err.Error())
if err != nil {
logger.Error("can't send log to manager", "err", err)
}

return nil, err

}
defer cursor.Close(ctx)

var finalResult []event.Event
if err := cursor.All(ctx, &finalResult); err != nil {
_, err := h.grpc.AddLog(context.Background(),
"database error while adding new event", err.Error())
if err != nil {
logger.Error("can't send log to manager", "err", err)
}

return nil, err

}

return finalResult, nil
Expand Down

0 comments on commit a0cf0ac

Please sign in to comment.