Skip to content

Commit

Permalink
add unsupported media type for mime type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
gilcrest committed May 6, 2024
1 parent 0054d5a commit 1a09bde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion errs/errs.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const (
// For Unauthorized errors, the response body should be empty.
// The error is logged and http.StatusForbidden (403) is sent.
Unauthorized
UnsupportedMediaType // Unsupported Media Type
)

func (k Kind) String() string {
Expand Down Expand Up @@ -185,8 +186,11 @@ func (k Kind) String() string {
return "unauthenticated request"
case Unauthorized:
return "unauthorized request"
case UnsupportedMediaType:
return "unsupported media type"
default:
return "unknown error kind"
}
return "unknown error kind"
}

// E builds an error value from its arguments.
Expand Down
2 changes: 2 additions & 0 deletions errs/httperrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ func httpErrorStatusCode(k Kind) int {
switch k {
case Invalid, Exist, NotExist, Private, BrokenLink, Validation, InvalidRequest:
return http.StatusBadRequest
case UnsupportedMediaType:
return http.StatusUnsupportedMediaType
// the zero value of Kind is Other, so if no Kind is present
// in the error, Other is used. Errors should always have a
// Kind set, otherwise, a 500 will be returned and no
Expand Down

0 comments on commit 1a09bde

Please sign in to comment.