Documentation
¶
Overview ¶
Package httperr provides a middleware to make it easier to handle http errors in a common way.
Index ¶
- func DefaultErrorHandler(w http.ResponseWriter, err error, status int)
- func Errorf(status int, format string, args ...interface{}) error
- func New(next Handler) http.Handler
- func NewF(next HandlerFunc) http.Handler
- func NewFWithHandler(next HandlerFunc, eh ErrorHandler) http.Handler
- func NewWithHandler(next Handler, eh ErrorHandler) http.Handler
- func Wrap(err error, status int) error
- type Error
- type ErrorHandler
- type Handler
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶ added in v1.3.0
func DefaultErrorHandler(w http.ResponseWriter, err error, status int)
DefaultErrorHandler is the default error handler. It converts the error to JSON and prints writes it to the response.
func NewF ¶
func NewF(next HandlerFunc) http.Handler
NewF wraps a given http.HandlerFunc and return a http.Handler.
func NewFWithHandler ¶ added in v1.3.0
func NewFWithHandler(next HandlerFunc, eh ErrorHandler) http.Handler
NewFWithHandler wraps a given http.HandlerFunc and return a http.Handler. You can also customize how the error is handled.
func NewWithHandler ¶ added in v1.3.0
func NewWithHandler(next Handler, eh ErrorHandler) http.Handler
NewWithHandler() wraps a given http.Handler and returns a http.Handler. You can also customize how the error is handled.
Types ¶
type ErrorHandler ¶ added in v1.3.0
type ErrorHandler func(w http.ResponseWriter, err error, status int)
ErrorHandler handles an error.
type Handler ¶
type Handler interface {
ServeHTTP(w http.ResponseWriter, r *http.Request) error
}
Handler is like http.Handler, but the ServeHTTP method can also return an error.
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
HandlerFunc is just like http.HandlerFunc.
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error
ServeHTTP calls f(w, r).