Documentation ¶
Overview ¶
Package httperror provides common basic building blocks for custom HTTP frameworks.
The API of this package is not stable at this time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NotHandle = errors.New("httperror: maybe HTTP handler chose to not handle request")
NotHandle is returned by a maybe HTTP handler to report that it explicitly chose to not handle the given HTTP request.
Functions ¶
func HandleBadRequest ¶
func HandleBadRequest(w http.ResponseWriter, err BadRequest)
HandleBadRequest handles a bad request error. The contents of err.Err are displayed to user, so you shouldn't include any sensitive information there, only information about the bad request.
func HandleMethod ¶
func HandleMethod(w http.ResponseWriter, err Method)
HandleMethod handles a method error.
Types ¶
type BadRequest ¶
type BadRequest struct {
Err error // Not nil.
}
BadRequest is an error type used for representing a bad request error.
func IsBadRequest ¶
func IsBadRequest(err error) (BadRequest, bool)
IsBadRequest reports if err is considered a bad request error, returning it if so.
type HTTP ¶
HTTP is an error type used for representing a non-nil error with a status code.
type Handler ¶
type Handler interface {
ServeHTTP(http.ResponseWriter, *http.Request) error
}
Handler is like http.Handler, but with an error return value.
If ServeHTTP returns a non-nil error value, the caller is expected to handle it in some way, taking into account whether the ResponseWriter was already written to.
type JSONResponse ¶
type JSONResponse struct {
V interface{}
}
JSONResponse is an error type used for representing a JSON response.
func IsJSONResponse ¶
func IsJSONResponse(err error) (JSONResponse, bool)
IsJSONResponse reports if err is considered a JSON response, returning it if so.
func (JSONResponse) Error ¶
func (JSONResponse) Error() string
type Method ¶
type Method struct {
Allowed []string // Allowed methods.
}
Method is an error type used for methods that aren't allowed.
type Redirect ¶
type Redirect struct {
URL string
}
Redirect is an error type used for representing a simple HTTP redirection.
func IsRedirect ¶
IsRedirect reports if err is considered a redirect, returning it if so.