From 1a09bdebac4a6f7bc3a3a8951f5605521ad7f2e0 Mon Sep 17 00:00:00 2001 From: Dan Gillis Date: Sun, 5 May 2024 22:09:41 -0400 Subject: [PATCH] add unsupported media type for mime type checking --- errs/errs.go | 6 +++++- errs/httperrors.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/errs/errs.go b/errs/errs.go index 8fd3205..55006a2 100644 --- a/errs/errs.go +++ b/errs/errs.go @@ -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 { @@ -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. diff --git a/errs/httperrors.go b/errs/httperrors.go index f296412..3f40a36 100644 --- a/errs/httperrors.go +++ b/errs/httperrors.go @@ -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