Skip to content

Commit

Permalink
Add error catcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Apr 14, 2021
1 parent 36494be commit 5c4080c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type Middleware interface {
}

// ErrorCatcher is a use case middleware that collects non empty errors.
type ErrorCatcher func(err error)
type ErrorCatcher func(ctx context.Context, input interface{}, err error)

// Wrap implements Middleware.
func (e ErrorCatcher) Wrap(interactor Interactor) Interactor {
return Interact(func(ctx context.Context, input, output interface{}) error {
err := interactor.Interact(ctx, input, output)
if err != nil {
e(err)
e(ctx, input, err)
}

return err
Expand Down
2 changes: 1 addition & 1 deletion wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestErrorCatcher_Wrap(t *testing.T) {
})

called := false
uw := usecase.Wrap(u, usecase.ErrorCatcher(func(err error) {
uw := usecase.Wrap(u, usecase.ErrorCatcher(func(ctx context.Context, input interface{}, err error) {
called = true
assert.EqualError(t, err, "failed")
}))
Expand Down

0 comments on commit 5c4080c

Please sign in to comment.