Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
ErrorResponse *ErrorResponse
}
Error is an error who occured when trying to validate an entity It contains an ErrorResponse which can be used to write an http error message.
func GetUnmarshalError ¶
func GetUnmarshalError(err *json.UnmarshalTypeError) *Error
GetUnmarshalError returns a validation Error based on given UnmarshalTypeError.
func NewError ¶
func NewError(errorResponse *ErrorResponse) *Error
NewError returns an error based on a validation error response.
type ErrorDetail ¶
ErrorDetail details an error.
func NewParameterErrorDetail ¶
func NewParameterErrorDetail(field, reason string) ErrorDetail
NewParameterErrorDetail returns an error struct containing which field and the reason behind the error.
func (*ErrorDetail) MarshalJSON ¶
func (errorDetail *ErrorDetail) MarshalJSON() ([]byte, error)
MarshalJSON marshals a JSON string from the ErrorResponse.
type ErrorResponse ¶
type ErrorResponse struct { Title string `json:"title"` Detail string `json:"detail,omitempty"` Status int `json:"status"` Type string `json:"type"` Details []ErrorDetail `json:"details,omitempty"` }
ErrorResponse is a generic response type for errors in HTTP requests.
func NewErrorResponse ¶
func NewErrorResponse(statusCode int, details ...ErrorDetail) *ErrorResponse
NewErrorResponse returns a new ErrorResponse based on given status code and details.
func (*ErrorResponse) MarshalJSON ¶
func (errorResponse *ErrorResponse) MarshalJSON() ([]byte, error)
MarshalJSON marshals a JSON string from the ErrorResponse.
func (*ErrorResponse) WriteHTTPError ¶
func (errorResponse *ErrorResponse) WriteHTTPError(writer http.ResponseWriter)
WriteHTTPError writes error to a writer as JSON.