package domain import ( "errors" "fmt" ) var ( ErrNothingToUpdate = errors.New("nothing to update") ErrRequired = errors.New("cannot be blank") ) type ErrorCode uint8 const ( ErrorCodeUnknown ErrorCode = iota ErrorCodeEntityNotFound ErrorCodeValidationError ErrorCodeAlreadyExists ) type Error interface { error UserError() string Code() ErrorCode } type ValidationError struct { Field string Err error } func (e ValidationError) Error() string { return fmt.Sprintf("%s: %s", e.Field, e.Err) } func (e ValidationError) UserError() string { return e.Error() } func (e ValidationError) Code() ErrorCode { return ErrorCodeValidationError } func (e ValidationError) Unwrap() error { return e.Err } type MinError struct { Min int } func (e MinError) Error() string { return fmt.Sprintf("must be no less than %d", e.Min) } func (e MinError) UserError() string { return e.Error() } func (e MinError) Code() ErrorCode { return ErrorCodeValidationError }