Documentation
¶
Index ¶
- func Send(w http.ResponseWriter, err interface{})
- type BadRequest
- type Conflict
- type Error
- type Forbidden
- type HandlerFunc
- type InternalServer
- type Logger
- type MethodNotAllowed
- type Middleware
- 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 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 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