Documentation
¶
Index ¶
- func Handler(next http.Handler) http.Handler
- func RenderError(w http.ResponseWriter, r *http.Request, err error)
- type HttpException
- func BadGateway(msg string) *HttpException
- func BadRequest(msg string) *HttpException
- func Conflict(msg string) *HttpException
- func Forbidden(msg string) *HttpException
- func GatewayTimeout(msg string) *HttpException
- func Gone(msg string) *HttpException
- func InternalServerError(msg string) *HttpException
- func NotFound(msg string) *HttpException
- func NotImplemented(msg string) *HttpException
- func ServiceUnavailable(msg string) *HttpException
- func TooManyRequests(msg string) *HttpException
- func Unauthorized(msg string) *HttpException
- func UnprocessableEntity(msg string) *HttpException
- func Wrap(code int, msg string, cause error) *HttpException
- func WrapWithReport(code int, msg string, cause error, reporter func() []string) *HttpException
- func (e *HttpException) Error() string
- func (e *HttpException) Render(w http.ResponseWriter, r *http.Request)
- func (e *HttpException) Report() []string
- func (e *HttpException) Unwrap() error
- func (e *HttpException) WithHeader(key, value string) *HttpException
- func (e *HttpException) WithReport(fn func() []string) *HttpException
- type Renderable
- type Reportable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderError ¶
func RenderError(w http.ResponseWriter, r *http.Request, err error)
RenderError is a convenience function to render any error as an HTTP response.
Types ¶
type HttpException ¶
HttpException represents a generic HTTP error.
func BadGateway ¶
func BadGateway(msg string) *HttpException
BadGateway returns a 502 HttpException.
func BadRequest ¶
func BadRequest(msg string) *HttpException
BadRequest returns a 400 HttpException.
func GatewayTimeout ¶
func GatewayTimeout(msg string) *HttpException
GatewayTimeout returns a 504 HttpException.
func InternalServerError ¶
func InternalServerError(msg string) *HttpException
InternalServerError returns a 500 HttpException.
func NotImplemented ¶
func NotImplemented(msg string) *HttpException
NotImplemented returns a 501 HttpException.
func ServiceUnavailable ¶
func ServiceUnavailable(msg string) *HttpException
ServiceUnavailable returns a 503 HttpException.
func TooManyRequests ¶
func TooManyRequests(msg string) *HttpException
TooManyRequests returns a 429 HttpException.
func Unauthorized ¶
func Unauthorized(msg string) *HttpException
Unauthorized returns a 401 HttpException.
func UnprocessableEntity ¶
func UnprocessableEntity(msg string) *HttpException
UnprocessableEntity returns a 422 HttpException.
func Wrap ¶
func Wrap(code int, msg string, cause error) *HttpException
Wrap creates an HttpException wrapping an underlying error.
func WrapWithReport ¶
func WrapWithReport(code int, msg string, cause error, reporter func() []string) *HttpException
WrapWithReport creates an HttpException wrapping an error with a reporter.
func (*HttpException) Error ¶
func (e *HttpException) Error() string
func (*HttpException) Render ¶
func (e *HttpException) Render(w http.ResponseWriter, r *http.Request)
Render outputs the exception as either JSON or HTML based on the request's Accept or Content-Type headers.
func (*HttpException) Report ¶
func (e *HttpException) Report() []string
Report returns additional context for logging.
func (*HttpException) Unwrap ¶
func (e *HttpException) Unwrap() error
func (*HttpException) WithHeader ¶
func (e *HttpException) WithHeader(key, value string) *HttpException
WithHeader adds a response header to the exception.
func (*HttpException) WithReport ¶
func (e *HttpException) WithReport(fn func() []string) *HttpException
WithReport adds a reporter function for custom log context.
type Renderable ¶
type Renderable interface {
error
Render(w http.ResponseWriter, r *http.Request)
}
Renderable is an interface for exceptions that can render themselves.
type Reportable ¶
Reportable is an interface for exceptions that can report themselves.