Documentation
¶
Index ¶
- func New(msg string) error
- func NewBadGatewayError(message string, err error) error
- func NewBadRequestError(message string, err error) error
- func NewConflictError(message string, err error) error
- func NewForbiddenError(message string, err error) error
- func NewGatewayTimeoutError(message string, err error) error
- func NewHTTPError(statusCode int, name, message string, err error) error
- func NewInternalServerError(message string, err error) error
- func NewNotFoundError(message string, err error) error
- func NewServiceUnavailableError(message string, err error) error
- func NewTooManyRequestsError(message string, err error) error
- func NewUnauthorizedError(message string, err error) error
- func NewWithName(name, msg string) error
- func NewWithNameAndErr(name, msg string, orig error) error
- func Wrap(err error) error
- type Error
- type GenericError
- type HTTPError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶ added in v1.0.0
New creates a new GenericError with it's name set to "error", the message set to the given message.
func NewBadGatewayError ¶
NewBadGatewayError creates a new HTTPError with a 502 status code.
func NewBadRequestError ¶
NewBadRequestError creates a new HTTPError with a 400 status code.
func NewConflictError ¶ added in v1.0.0
NewConflictError creates a new HTTPError with a 409 status code.
func NewForbiddenError ¶
NewForbiddenError creates a new HTTPError with a 403 status code.
func NewGatewayTimeoutError ¶
NewGatewayTimeoutError creates a new HTTPError with a 504 status code.
func NewHTTPError ¶ added in v1.0.0
NewHTTPError creates a new HTTPError.
func NewInternalServerError ¶
NewInternalServerError creates a new HTTPError with a 500 status code.
func NewNotFoundError ¶
NewNotFoundError creates a new HTTPError with a 404 status code.
func NewServiceUnavailableError ¶ added in v1.0.0
NewServiceUnavailableError creates a new HTTPError with a 503 status code.
func NewTooManyRequestsError ¶ added in v1.0.0
NewTooManyRequestsError creates a new HTTPError with a 429 status code.
func NewUnauthorizedError ¶
NewUnauthorizedError creates a new HTTPError with a 401 status code.
func NewWithName ¶ added in v1.0.0
NewWithName creates a new GenericError with it's name set to the given name and the message set to the given message.
func NewWithNameAndErr ¶ added in v1.0.0
NewWithNameAndErr creates a new GenericError with it's name set to the given name, the message set to the given message and the original property set to the given original error.
Types ¶
type Error ¶
type Error interface {
// ensures that the error implements the error interface
error
// JSON returns the JSON representation of the error
// and it must ensure that the returned value is
// is a valid JSON even if the error is not marshallable
// by handling the error returned by json.Marshal
JSON() []byte
}
Error is an interface for errors that can be marshalled to JSON
type GenericError ¶ added in v1.0.0
type GenericError struct {
// Name is the name of the error
Name string `json:"name"`
// Message is the message of the error
Message string `json:"message"`
// Original is an optional original error
Original error `json:"original,omitempty"`
}
func (GenericError) Error ¶ added in v1.0.0
func (e GenericError) Error() string
Error returns a string concatenation of the name, message and original error.
func (GenericError) JSON ¶ added in v1.0.0
func (e GenericError) JSON() []byte
JSON returns the JSON representation of the error
If the Orginal property is not marshallable, it will be replaced with a marshallable error indicating why the original error is not marshallable and it's original error returned by the Error() method.
type HTTPError ¶ added in v1.0.0
type HTTPError struct {
StatusCode int `json:"statusCode"`
Name string `json:"name"`
Message string `json:"message"`
Err error `json:"error"`
}
HTTPError is a struct that represents an HTTP error and it implements the Error interface.
func (*HTTPError) Error ¶ added in v1.0.0
Error returns a string concatenation of the name and message. If th Err property is not nil, it will be returned in the message.
func (HTTPError) JSON ¶ added in v1.0.0
JSON returns the bytes of the JSON representation of the error.
If the Err property is not marshalable, it will be replaced with a marshalable error indicating why it is not marshalable.
If the Err property is not an implementation of the Error interface, it will be replaced with a wrapped version of it to ensure that the error is marshallable and content will be shown.