Skip to content

Commit

Permalink
Simplified error handling in commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragana Berber Krizik committed Oct 17, 2023
1 parent 2004115 commit 0f922e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ func CreateRedirectsHandler(repo *redirectrepository.RedirectsDefinitionReposito
}
oldDefinitions, err := repo.FindAll(ctx)
if err != nil {
l.Error(err.Error())
l.Error("failed to fetch existing definitions", zap.Error(err))
return err
}
l.Info("calling consolidate automatic redirects")
consolidatedDefs, deletedDefs := redirectdefinitionutils.ConsolidateRedirectDefinitions(l, *oldDefinitions, newDefinitions)

updateErr := repo.UpsertMany(ctx, &consolidatedDefs)
if updateErr != nil {
l.Error("failed to UpsertMany", zap.Error(updateErr))
l.Error("failed to updated definitions", zap.Error(updateErr))
return updateErr
}

deleteErr := repo.DeleteMany(ctx, deletedDefs)
if deleteErr != nil {
l.Error("failed to DeleteMany", zap.Error(deleteErr))
l.Error("failed to delete definitions", zap.Error(deleteErr))
return deleteErr
}
l.Info("successfully finished create automatic redirects")
Expand Down
6 changes: 1 addition & 5 deletions domain/redirectdefinition/query/getredirects.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ type (
// GetRedirectsHandler ...
func GetRedirectsHandler(repo *redirectrepository.RedirectsDefinitionRepository) GetRedirectsHandlerFn {
return func(ctx context.Context, l *zap.Logger) (*redirectstore.RedirectDefinitions, error) {
defs, err := repo.FindAll(ctx)
if err != nil {
return nil, err
}
return defs, nil
return repo.FindAll(ctx)
}
}

Expand Down
6 changes: 1 addition & 5 deletions domain/redirectdefinition/query/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ type (
// SearchHandler ...
func SearchHandler(repo *redirectrepository.RedirectsDefinitionRepository) SearchHandlerFn {
return func(ctx context.Context, l *zap.Logger, qry Search) (*redirectstore.RedirectDefinition, error) {
definition, err := repo.Find(ctx, qry.ID, string(qry.Source))
if err != nil {
return nil, err
}
return definition, nil
return repo.Find(ctx, qry.ID, string(qry.Source))
}
}

Expand Down

0 comments on commit 0f922e8

Please sign in to comment.