Documentation ¶
Overview ¶
Package httperr adds idiomatic error handling to net/http and httprouter Handle(r)s.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Formatf ¶
Formatf returns an error that induces this package's Handle(r)s to send the specified HTTP code. If the code is 200, the returned error is nil. Only 400-level codes have their messages propagated. All other codes result in the error message being hashed and logged, with only a portion of the hash returned to the end user for reporting.
func HandlerFunc ¶
func HandlerFunc(fn func(http.ResponseWriter, *http.Request) error) http.HandlerFunc
HandlerFunc allows http.HandlerFunc-like functions to return errors. If the returned error is one returned by Formatf(), it is treated as described in that function's documentation. All other errors are treated as 500.
func RouterHandle ¶
func RouterHandle(fn func(http.ResponseWriter, *http.Request, httprouter.Params) error) httprouter.Handle
RouterHandle is equivalent to HandlerFunc, but also supports propagation of httprouter.Params.
func WithStatus ¶
WithStatus converts err into an error with the same behaviour as those returned by Formatf().
Types ¶
This section is empty.