Skip to content

Commit

Permalink
Introduce ErrorHandlerFunc (go-kit#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
maratori authored and peterbourgon committed Oct 3, 2019
1 parent f72181f commit 0fadbe9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions transport/error_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ func NewLogErrorHandler(logger log.Logger) *LogErrorHandler {
func (h *LogErrorHandler) Handle(ctx context.Context, err error) {
h.logger.Log("err", err)
}

// The ErrorHandlerFunc type is an adapter to allow the use of
// ordinary function as ErrorHandler. If f is a function
// with the appropriate signature, ErrorHandlerFunc(f) is a
// ErrorHandler that calls f.
type ErrorHandlerFunc func(ctx context.Context, err error)

// Handle calls f(ctx, err).
func (f ErrorHandlerFunc) Handle(ctx context.Context, err error) {
f(ctx, err)
}

0 comments on commit 0fadbe9

Please sign in to comment.