Documentation
¶
Index ¶
- func As(err error, target interface{}) bool
- func Is(err, target error) bool
- func New(text string) error
- func Send(w http.ResponseWriter, err interface{})
- func Unwrap(err error) error
- type BadRequest
- type Conflict
- type Error
- type Forbidden
- type HandlerFunc
- type InternalServer
- type Logger
- type MethodNotAllowed
- type Middleware
- type NotAcceptable
- type NotFound
- type NotImplemented
- type RequestTimeout
- type ResponseLogger
- type Sender
- type StatusError
- type Unauthorized
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v1.1.0
As finds the first error in err's chain that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false. Wraps original errors.As function to avoid importing "errors".
func Is ¶ added in v1.1.0
Is reports whether any error in err's chain matches target. Wraps original errors.Is function to avoid importing "errors".
func New ¶ added in v1.1.0
New returns an error that formats as the given text. Wraps original errors.New function to avoid importing "errors".
func Send ¶
func Send(w http.ResponseWriter, err interface{})
Send provided argument as an HTTP error to the client (retrieving status code if available). If status code cannot be retrieved it sends error with status 500 by default . If value does not implement any of supported error interfaces (error/Error) - it tries to convert the value to a string.
Types ¶
type BadRequest ¶
type BadRequest string
BadRequest is a 400 HTTP error.
func BadRequestf ¶
func BadRequestf(format string, args ...interface{}) BadRequest
BadRequestf returns formatted BadRequest error.
func NewBadRequest ¶
func NewBadRequest(cause error) BadRequest
NewBadRequest is a constructor func for 400 HTTP error.
func (BadRequest) Error ¶
func (e BadRequest) Error() string
type Conflict ¶
type Conflict string
Conflict is a 409 HTTP error.
func NewConflict ¶
NewConflict is a constructor func for 409 HTTP error.
type Forbidden ¶
type Forbidden string
Forbidden is a 403 HTTP error.
func Forbiddenf ¶
Forbiddenf returns formatted Forbidden error.
func NewForbidden ¶
NewForbidden is a constructor func for 403 HTTP error.
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, message string, code int)
HandlerFunc is an error handler function, for instance http.Error
type InternalServer ¶
type InternalServer string
InternalServer is a 500 HTTP error.
func InternalServerf ¶
func InternalServerf(format string, args ...interface{}) InternalServer
InternalServerf returns formatted InternalServer error.
func NewInternalServer ¶
func NewInternalServer(cause error) InternalServer
NewInternalServer is a constructor func for 500 HTTP error.
func (InternalServer) Error ¶
func (e InternalServer) Error() string
type MethodNotAllowed ¶
type MethodNotAllowed string
MethodNotAllowed is a 404 HTTP error.
func MethodNotAllowedf ¶
func MethodNotAllowedf(format string, args ...interface{}) MethodNotAllowed
MethodNotAllowedf returns formatted MethodNotAllowed error.
func NewMethodNotAllowed ¶
func NewMethodNotAllowed(cause error) MethodNotAllowed
NewMethodNotAllowed is a constructor func for 405 HTTP error.
func (MethodNotAllowed) Error ¶
func (e MethodNotAllowed) Error() string
type Middleware ¶
Middleware is a chainable sender wrapper func.
func WithLogger ¶
func WithLogger(logger Logger) Middleware
WithLogger wrapps provided sender with logger.
Example: errors.LoggerWrapper(logger)(errors.Send)(w, err)
type NotAcceptable ¶ added in v1.2.0
type NotAcceptable string
NotAcceptable is a 406 HTTP error.
func NewNotAcceptable ¶ added in v1.2.0
func NewNotAcceptable(cause error) NotAcceptable
NewMethodNotAllowed is a constructor func for 406 HTTP error.
func NotAcceptablef ¶ added in v1.2.0
func NotAcceptablef(format string, args ...interface{}) NotAcceptable
NotAcceptablef returns formatted NotAcceptable error.
func (NotAcceptable) Code ¶ added in v1.2.0
func (e NotAcceptable) Code() int
Code returns HTTP status code.
func (NotAcceptable) Error ¶ added in v1.2.0
func (e NotAcceptable) Error() string
type NotFound ¶
type NotFound string
NotFound is a 404 HTTP error.
func NewNotFound ¶
NewNotFound is a constructor func for 404 HTTP error.
type NotImplemented ¶
type NotImplemented string
NotImplemented is a 501 HTTP error.
func NewNotImplemented ¶
func NewNotImplemented(cause error) NotImplemented
NewNotImplemented is a constructor func for 501 HTTP error.
func NotImplementedf ¶
func NotImplementedf(format string, args ...interface{}) NotImplemented
NotImplementedf returns formatted NotImplemented error.
func (NotImplemented) Error ¶
func (e NotImplemented) Error() string
type RequestTimeout ¶
type RequestTimeout string
RequestTimeout is a 404 HTTP error.
func NewRequestTimeout ¶
func NewRequestTimeout(cause error) RequestTimeout
NewRequestTimeout is a constructor func for 408 HTTP error.
func RequestTimeoutf ¶
func RequestTimeoutf(format string, args ...interface{}) RequestTimeout
RequestTimeoutf returns formatted RequestTimeout error.
func (RequestTimeout) Error ¶
func (e RequestTimeout) Error() string
type ResponseLogger ¶
type ResponseLogger struct{ Logger }
ResponseLogger provides another (object oriented) approach to log the error.
Example: (&errors.ResponseLogger{Logger: logger}).Log(errors.Send)(w, err)
func (*ResponseLogger) Log ¶
func (rl *ResponseLogger) Log(sender Sender) Sender
Log creates Sender middleware func.
type Sender ¶
type Sender func(http.ResponseWriter, interface{})
Sender is a function that sends an error through the provided response writer.
type StatusError ¶
type StatusError struct {
// contains filtered or unexported fields
}
StatusError is a basic Error interface implementation.
func NewStatusError ¶
func NewStatusError(code int, cause error) StatusError
NewStatusError is a constructor func for StatusError.
func (StatusError) Code ¶
func (e StatusError) Code() int
Code returns HTTP status code (to satisfy Error interface).
type Unauthorized ¶
type Unauthorized string
Unauthorized is a 401 HTTP error.
func NewUnauthorized ¶
func NewUnauthorized(cause error) Unauthorized
NewUnauthorized is a constructor func for 401 HTTP error.
func Unauthorizedf ¶
func Unauthorizedf(format string, args ...interface{}) Unauthorized
Unauthorizedf returns formatted Unauthorized error.
func (Unauthorized) Error ¶
func (e Unauthorized) Error() string