checkpoint: moved the invalid status content type error to model
This commit is contained in:
parent
d660081f3e
commit
e75468b6fa
5 changed files with 28 additions and 21 deletions
|
@ -173,9 +173,9 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedContentType := model.ParseStatusContentType(c.contentType)
|
parsedContentType, err := model.ParseStatusContentType(c.contentType)
|
||||||
if parsedContentType == model.StatusContentTypeUnknown {
|
if err != nil {
|
||||||
return InvalidStatusContentTypeError{ContentType: c.contentType}
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
form := client.CreateStatusForm{
|
form := client.CreateStatusForm{
|
||||||
|
|
|
@ -58,11 +58,3 @@ func (e EmptyContentError) Error() string {
|
||||||
|
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
type InvalidStatusContentTypeError struct {
|
|
||||||
ContentType string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e InvalidStatusContentTypeError) Error() string {
|
|
||||||
return "'" + e.ContentType + "' is an invalid status content type (valid values are plain and markdown)"
|
|
||||||
}
|
|
||||||
|
|
|
@ -95,10 +95,10 @@ type InvalidListRepliesPolicyError struct {
|
||||||
func (e InvalidListRepliesPolicyError) Error() string {
|
func (e InvalidListRepliesPolicyError) Error() string {
|
||||||
return "'" +
|
return "'" +
|
||||||
e.Value +
|
e.Value +
|
||||||
"' is not a valid list replies policy (valid values are " +
|
"' is not a valid list replies policy: valid values are " +
|
||||||
listRepliesPolicyFollowedValue + ", " +
|
listRepliesPolicyFollowedValue + ", " +
|
||||||
listRepliesPolicyListValue + ", " +
|
listRepliesPolicyListValue + ", " +
|
||||||
listRepliesPolicyNoneValue + ")"
|
listRepliesPolicyNoneValue
|
||||||
}
|
}
|
||||||
|
|
||||||
type List struct {
|
type List struct {
|
||||||
|
|
|
@ -38,22 +38,37 @@ func (s StatusContentType) String() string {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseStatusContentType(value string) StatusContentType {
|
func ParseStatusContentType(value string) (StatusContentType, error) {
|
||||||
switch value {
|
switch value {
|
||||||
case statusContentTypePlainValue, statusContentTypeTextPlainValue:
|
case statusContentTypePlainValue, statusContentTypeTextPlainValue:
|
||||||
return StatusContentTypePlainText
|
return StatusContentTypePlainText, nil
|
||||||
case statusContentTypeMarkdownValue, statusContentTypeTextMarkdownValue:
|
case statusContentTypeMarkdownValue, statusContentTypeTextMarkdownValue:
|
||||||
return StatusContentTypeMarkdown
|
return StatusContentTypeMarkdown, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return StatusContentTypeUnknown
|
return StatusContentTypeUnknown, InvalidStatusContentTypeError{Value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StatusContentType) MarshalJSON() ([]byte, error) {
|
func (s StatusContentType) MarshalJSON() ([]byte, error) {
|
||||||
value := s.String()
|
value := s.String()
|
||||||
if value == unknownValue {
|
if value == unknownValue {
|
||||||
return nil, fmt.Errorf("%q is not a valid status content type", value)
|
return nil, InvalidStatusContentTypeError{Value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Marshal(value)
|
data, err := json.Marshal(value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to encode %s to JSON: %w", value, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type InvalidStatusContentTypeError struct {
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e InvalidStatusContentTypeError) Error() string {
|
||||||
|
return "'" + e.Value + "' is an invalid status content type: valid values are " +
|
||||||
|
statusContentTypePlainValue + " or " + statusContentTypeTextPlainValue + " for plain text, or " +
|
||||||
|
statusContentTypeMarkdownValue + " or " + statusContentTypeTextMarkdownValue + " for Markdown"
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,10 +98,10 @@ type InvalidStatusVisibilityError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e InvalidStatusVisibilityError) Error() string {
|
func (e InvalidStatusVisibilityError) Error() string {
|
||||||
return "'" + e.Value + "' is not a valid status visibility value (valid values are " +
|
return "'" + e.Value + "' is not a valid status visibility value: valid values are " +
|
||||||
statusVisibilityPublicValue + ", " +
|
statusVisibilityPublicValue + ", " +
|
||||||
statusVisibilityUnlistedValue + ", " +
|
statusVisibilityUnlistedValue + ", " +
|
||||||
statusVisibilityPrivateValue + ", " +
|
statusVisibilityPrivateValue + ", " +
|
||||||
statusVisibilityMutualsOnlyValue + ", " +
|
statusVisibilityMutualsOnlyValue + ", " +
|
||||||
statusVisibilityDirectValue + ")"
|
statusVisibilityDirectValue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue