httperr

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package httperr is in need of a good package description

Index

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 Annotate

func Annotate(err error, text string) *Error

func Annotatef

func Annotatef(err error, text string, args ...interface{}) *Error

func Errorf

func Errorf(text string, args ...interface{}) *Error

Errorf is a convenience wrapper around NewError(fmt.Sprintf(text, args...)).

func LogErrorf

func LogErrorf(text string, args ...interface{}) *Error

LogErrorf is a convenience wrapper around Errorf(text, args...).Log()

func LogWithError

func LogWithError(err error, options ...Option) *Error

func New

func New(text string, options ...Option) *Error

New is a convenience wrapper around NewError(text).WithOptions(options...).

func NewError

func NewError(text string) *Error

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

func WithError(err error, options ...Option) *Error

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) Annotate

func (e *Error) Annotate(text string) *Error

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

func (*Error) Log

func (e *Error) Log() *Error

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

func (e *Error) WithOptions(options ...Option) *Error

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 LogLevel

type LogLevel int
const (
	LogNone LogLevel = iota
	LogInfo
	LogWarning
	LogError
	LogFatal
)

func LogVerbose

func LogVerbose(v log.Level) LogLevel

type Message

type Message struct {
	// contains filtered or unexported fields
}
var (
	HTTPMessage  *Message
	ErrorMessage = &Message{""}
)

func AltMessage

func AltMessage(text string) *Message

func AltMessagef

func AltMessagef(text string, args ...interface{}) *Message

type Option

type Option interface {
	// contains filtered or unexported methods
}

type Status

type Status int
const StatusNone Status = 0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL