Documentation
¶
Index ¶
Constants ¶
const (
ErrCodeParsingBody = "error_parsing_body"
)
Variables ¶
This section is empty.
Functions ¶
func Wrapper ¶
func Wrapper( log zerolog.Logger, f TypedHandler, ) http.HandlerFunc
Wrapper will actually do the boring work of logging an error and render the response.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error error `json:"-"`
HTTPStatusCode int `json:"-"`
ErrorCode string `json:"error_code"`
ErrorMsg string `json:"error_msg"`
}
ErrorResponse is a wrapper for the error response body to have a clean way of displaying errors.
func BindBody ¶
func BindBody(r *http.Request, target interface{}) *ErrorResponse
BindBody will bind the body of the request to the given interface.
func NewErrorResponse ¶
func NewErrorResponse( e error, hsc int, ec string, msg string, ) *ErrorResponse
NewErrorResponse creates a new ErrorResponse.
func (*ErrorResponse) IsEqual ¶
func (her *ErrorResponse) IsEqual(e1 *ErrorResponse) bool
IsEqual checks if an error response is equal to another.
type InternalServerError ¶
type InternalServerError struct {
Err error
}
InternalServerError is an error that is returned when an internal server error occurs.
func (InternalServerError) Error ¶
func (e InternalServerError) Error() string
func (InternalServerError) ToErrorResponse ¶
func (e InternalServerError) ToErrorResponse() *ErrorResponse
type MissingParamError ¶
type MissingParamError struct {
Name string
}
MissingParamError is the error that is returned when a named URL param is missing.
func (MissingParamError) Error ¶
func (e MissingParamError) Error() string
func (MissingParamError) ToErrorResponse ¶
func (e MissingParamError) ToErrorResponse() *ErrorResponse
type NamedURLParamsGetter ¶
type NamedURLParamsGetter func(ctx context.Context, key string) (string, *ErrorResponse)
NamedURLParamsGetter is the interface that is used to parse the URL parameters.
type NotFoundError ¶
type NotFoundError struct {
Designation string
}
NotFoundError is an error that is returned when a resource is not found.
func (NotFoundError) Error ¶
func (e NotFoundError) Error() string
func (NotFoundError) ToErrorResponse ¶
func (e NotFoundError) ToErrorResponse() *ErrorResponse
type ParsingParamError ¶
ParsingParamError is the error that is returned when a named URL param is invalid.
func (ParsingParamError) Error ¶
func (e ParsingParamError) Error() string
func (ParsingParamError) ToErrorResponse ¶
func (e ParsingParamError) ToErrorResponse() *ErrorResponse
type TypedHandler ¶
type TypedHandler func(r *http.Request) (*Response, *ErrorResponse)
TypedHandler is the handler that you are actually handling the response.