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
|
||||
}
|
||||
|
||||
parsedContentType := model.ParseStatusContentType(c.contentType)
|
||||
if parsedContentType == model.StatusContentTypeUnknown {
|
||||
return InvalidStatusContentTypeError{ContentType: c.contentType}
|
||||
parsedContentType, err := model.ParseStatusContentType(c.contentType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
form := client.CreateStatusForm{
|
||||
|
|
|
@ -58,11 +58,3 @@ func (e EmptyContentError) Error() string {
|
|||
|
||||
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 {
|
||||
return "'" +
|
||||
e.Value +
|
||||
"' is not a valid list replies policy (valid values are " +
|
||||
"' is not a valid list replies policy: valid values are " +
|
||||
listRepliesPolicyFollowedValue + ", " +
|
||||
listRepliesPolicyListValue + ", " +
|
||||
listRepliesPolicyNoneValue + ")"
|
||||
listRepliesPolicyNoneValue
|
||||
}
|
||||
|
||||
type List struct {
|
||||
|
|
|
@ -38,22 +38,37 @@ func (s StatusContentType) String() string {
|
|||
return output
|
||||
}
|
||||
|
||||
func ParseStatusContentType(value string) StatusContentType {
|
||||
func ParseStatusContentType(value string) (StatusContentType, error) {
|
||||
switch value {
|
||||
case statusContentTypePlainValue, statusContentTypeTextPlainValue:
|
||||
return StatusContentTypePlainText
|
||||
return StatusContentTypePlainText, nil
|
||||
case statusContentTypeMarkdownValue, statusContentTypeTextMarkdownValue:
|
||||
return StatusContentTypeMarkdown
|
||||
return StatusContentTypeMarkdown, nil
|
||||
}
|
||||
|
||||
return StatusContentTypeUnknown
|
||||
return StatusContentTypeUnknown, InvalidStatusContentTypeError{Value: value}
|
||||
}
|
||||
|
||||
func (s StatusContentType) MarshalJSON() ([]byte, error) {
|
||||
value := s.String()
|
||||
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 {
|
||||
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 + ", " +
|
||||
statusVisibilityUnlistedValue + ", " +
|
||||
statusVisibilityPrivateValue + ", " +
|
||||
statusVisibilityMutualsOnlyValue + ", " +
|
||||
statusVisibilityDirectValue + ")"
|
||||
statusVisibilityDirectValue
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue