Documentation ¶
Index ¶
- Constants
- func GetKey(err error) string
- func GetMessage(err error) string
- func HTTPCode(err error) int
- func Is(err error, key string) bool
- func IsForbidden(err error) bool
- func IsResourceAlreadyExists(err error) bool
- func IsResourceNotFound(err error) bool
- func IsUnauthorized(err error) bool
- func IsWrongInputParameter(err error) bool
- type UError
Constants ¶
const ( GenericError = "Error" ResourceAlreadyExistsError = "ResourceAlreadyExistsError" ResourceNotFoundError = "ResourceNotFoundError" WrongInputParameterError = "WrongInputParameterError" ForbiddenError = "ForbiddenError" )
Variables ¶
This section is empty.
Functions ¶
func GetKey ¶
GetKey returns the key of the error if it is an UError or empty string if it is another error type.
func GetMessage ¶
GetMessage returns the message of the error if it is an UError, err.Error() otherwise.
func IsForbidden ¶
IsForbidden returns true if the error is a ForbiddenError.
func IsResourceAlreadyExists ¶
IsResourceAlreadyExists returns true if the error is a IsResourceAlreadyExists.
func IsResourceNotFound ¶
IsResourceNotFound returns true if the error is a ResourceNotFoundError.
func IsUnauthorized ¶
IsUnauthorized returns true if the error is a UnauthorizedError.
func IsWrongInputParameter ¶
IsWrongInputParameter returns true if the error is a WrongInputParameterError.
Types ¶
type UError ¶
type UError struct {
// contains filtered or unexported fields
}
func (*UError) MarshalJSON ¶
nolint:lll // long line needed MarshalJSON returns the json representation of the error, adding a parent key "error". Example 1: using a fmt.Errorf(...) as error cause. err := NewError("myKey", "myMessage").Cause(fmt.Errorf("myCause")) err.MarshalJSON() => {"error":{"key":"myKey","message":"myMessage","cause":"myCause"}}
Example 2: using another UError as error cause. err := NewError("myKey", "myMessage").Cause(NewError("myCauseKey", "myCauseMessage")) err.MarshalJSON() => {"error":{"key":"myKey","message":"myMessage","cause":{"error":{"key":"myKey","message":"myMessage"}}}}
func (*UError) UnmarshalJSON ¶
UnmarshalJSON builds a UError by calling FromBytes.