Documentation
¶
Overview ¶
Package httperr is in need of a good package description
Index ¶
- func Handler(hfunc HandlerFunc) http.HandlerFunc
- type Error
- func Abort(w http.ResponseWriter, err error, options ...Option) *Error
- func Annotate(err error, text string) *Error
- func Annotatef(err error, text string, args ...interface{}) *Error
- func Errorf(text string, args ...interface{}) *Error
- func LogErrorf(text string, args ...interface{}) *Error
- func LogWithError(err error, options ...Option) *Error
- func New(text string, options ...Option) *Error
- func NewError(text string) *Error
- func WithError(err error, options ...Option) *Error
- type HandlerFunc
- type LogLevel
- type Message
- type Option
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(hfunc HandlerFunc) http.HandlerFunc
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error... needs to be better documented.
func Abort ¶
func Abort(w http.ResponseWriter, err error, options ...Option) *Error
Abort is a wrapper around WithError(err, options).Abort(w). See the Abort method for details.
func LogWithError ¶
func NewError ¶
NewError returns a new Error that formats as the given text and applies the default options Status(http.StatusInternalServerError) and LogError. For different option values, use New instead of NewError -- or, you may call WithOptions on the return value to modify its options.
func WithError ¶
WithError returns err as an *Error or nil if err is nil. If err is already and Error, its type assertion is taken, otherwise, err is used to create a new Error. If any options are provided they override those from an existing Error or are applied to a newly created Error. If a new Error is created and no options are given, default options (as from NewError) are applied.
func (*Error) Abort ¶
func (e *Error) Abort(w http.ResponseWriter) *Error
Abort is a wrapper around both Send and Log. If e is non-nil, Send will be called to deliver an http error to w. It then makes a final attempt to log the error by calling Log. If this error has previously been logged, no log message will be emitted. If e is nil, nothing will be done. Either way, e will be returned.
func (*Error) Log ¶
Log emits a log message containing the text for the attached error at the level specified by the LogLevel option then returns e. Each error may only be logged once; if e has already been logged, no message will be written.
If the LogLevel option is LogNone, no log message will be written -- but e will still be marked as logged nonetheless. If the LogLevel option is later updated, the log message will continue to be suppressed on repeated calls to Log.
A call to one of the Annotate* functions will clear this flag and allow another log message to be emitted.
func (*Error) Send ¶
func (e *Error) Send(w http.ResponseWriter) *Error
Send calls http.Error using w, a derived error message and the http status code attached to e -- if and only if both e and w are non-nil and e's status code is a valid http status (as determined by calling http.StatusText). If any of these tests fail, nothing will be done. Otherwise, the error message will be derived based on one of the following Message option values:
* HTTPMessage: The results from http.StatusText will be used. (default) * ErrorMessage: The result of calling e.Error will be used. * AltMessage: The alternative message text will be used.
func (*Error) WithOptions ¶
WithOptions applies all options to e and returns the results. Note that the return value is a mere convenience; the reciever will also be modified.
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
type Message ¶
type Message struct {
// contains filtered or unexported fields
}