Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultErrorHandler = ErrorHandlerFunc(func(w http.ResponseWriter, r *http.Request, err error) { if err, ok := err.(httperror.HttpError); ok { http.Error(w, err.Error(), err.StatusCode()) return } http.Error(w, err.Error(), http.StatusInternalServerError) })
DefaultErrorHandler is the default error handler.
Functions ¶
func WithErrorHandler ¶
func WithErrorHandler(errorHandler ErrorHandler) func(HandlerFunc) http.HandlerFunc
WithErrorHandler returns an http.Handler that handles errors by errorHandler.
Types ¶
type ErrorHandler ¶
type ErrorHandler interface {
ServeHTTP(w http.ResponseWriter, r *http.Request, err error)
}
ErrorHandler is an interface that can handle errors returned by an Handler.
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
ErrorHandlerFunc is an adapter to handle errors returned by an Handler.
func (ErrorHandlerFunc) ServeHTTP ¶
func (f ErrorHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err error)
type Handler ¶
type Handler interface {
ServeHTTP(w http.ResponseWriter, r *http.Request) error
}
Handler is like http.Handler, but with an additional error return value.
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
HandlerFunc is an adapter to allow the use of ordinary functions as HTTP handlers.
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error
Click to show internal directories.
Click to hide internal directories.