...

Source file src/github.com/go-kit/kit/transport/error_handler.go

Documentation: github.com/go-kit/kit/transport

     1  package transport
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/go-kit/log"
     7  )
     8  
     9  // ErrorHandler receives a transport error to be processed for diagnostic purposes.
    10  // Usually this means logging the error.
    11  type ErrorHandler interface {
    12  	Handle(ctx context.Context, err error)
    13  }
    14  
    15  // LogErrorHandler is a transport error handler implementation which logs an error.
    16  type LogErrorHandler struct {
    17  	logger log.Logger
    18  }
    19  
    20  func NewLogErrorHandler(logger log.Logger) *LogErrorHandler {
    21  	return &LogErrorHandler{
    22  		logger: logger,
    23  	}
    24  }
    25  
    26  func (h *LogErrorHandler) Handle(ctx context.Context, err error) {
    27  	h.logger.Log("err", err)
    28  }
    29  
    30  // The ErrorHandlerFunc type is an adapter to allow the use of
    31  // ordinary function as ErrorHandler. If f is a function
    32  // with the appropriate signature, ErrorHandlerFunc(f) is a
    33  // ErrorHandler that calls f.
    34  type ErrorHandlerFunc func(ctx context.Context, err error)
    35  
    36  // Handle calls f(ctx, err).
    37  func (f ErrorHandlerFunc) Handle(ctx context.Context, err error) {
    38  	f(ctx, err)
    39  }
    40  

View as plain text