mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Add error helpers and constants for NotAcceptable and UnsupportedMediaType
This commit is contained in:
parent
d3428a5736
commit
037eec3b9a
@ -352,6 +352,14 @@ func NewGenericServerResponse(code int, verb string, qualifiedResource schema.Gr
|
||||
reason = metav1.StatusReasonForbidden
|
||||
// the server message has details about who is trying to perform what action. Keep its message.
|
||||
message = serverMessage
|
||||
case http.StatusNotAcceptable:
|
||||
reason = metav1.StatusReasonNotAcceptable
|
||||
// the server message has details about what types are acceptable
|
||||
message = serverMessage
|
||||
case http.StatusUnsupportedMediaType:
|
||||
reason = metav1.StatusReasonUnsupportedMediaType
|
||||
// the server message has details about what types are acceptable
|
||||
message = serverMessage
|
||||
case http.StatusMethodNotAllowed:
|
||||
reason = metav1.StatusReasonMethodNotAllowed
|
||||
message = "the server does not allow this method on the requested resource"
|
||||
@ -434,6 +442,16 @@ func IsResourceExpired(err error) bool {
|
||||
return ReasonForError(err) == metav1.StatusReasonExpired
|
||||
}
|
||||
|
||||
// IsNotAcceptable determines if err is an error which indicates that the request failed due to an invalid Accept header
|
||||
func IsNotAcceptable(err error) bool {
|
||||
return ReasonForError(err) == metav1.StatusReasonNotAcceptable
|
||||
}
|
||||
|
||||
// IsUnsupportedMediaType determines if err is an error which indicates that the request failed due to an invalid Content-Type header
|
||||
func IsUnsupportedMediaType(err error) bool {
|
||||
return ReasonForError(err) == metav1.StatusReasonUnsupportedMediaType
|
||||
}
|
||||
|
||||
// IsMethodNotSupported determines if the err is an error which indicates the provided action could not
|
||||
// be performed because it is not supported by the server.
|
||||
func IsMethodNotSupported(err error) bool {
|
||||
|
@ -651,6 +651,18 @@ const (
|
||||
// can only be created. API calls that return MethodNotAllowed can never succeed.
|
||||
StatusReasonMethodNotAllowed StatusReason = "MethodNotAllowed"
|
||||
|
||||
// StatusReasonNotAcceptable means that the accept types indicated by the client were not acceptable
|
||||
// to the server - for instance, attempting to receive protobuf for a resource that supports only json and yaml.
|
||||
// API calls that return NotAcceptable can never succeed.
|
||||
// Status code 406
|
||||
StatusReasonNotAcceptable StatusReason = "NotAcceptable"
|
||||
|
||||
// StatusReasonUnsupportedMediaType means that the content type sent by the client is not acceptable
|
||||
// to the server - for instance, attempting to send protobuf for a resource that supports only json and yaml.
|
||||
// API calls that return UnsupportedMediaType can never succeed.
|
||||
// Status code 415
|
||||
StatusReasonUnsupportedMediaType StatusReason = "UnsupportedMediaType"
|
||||
|
||||
// StatusReasonInternalError indicates that an internal error occurred, it is unexpected
|
||||
// and the outcome of the call is unknown.
|
||||
// Details (optional):
|
||||
|
@ -41,7 +41,7 @@ func (e errNotAcceptable) Status() metav1.Status {
|
||||
return metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: http.StatusNotAcceptable,
|
||||
Reason: metav1.StatusReason("NotAcceptable"),
|
||||
Reason: metav1.StatusReasonNotAcceptable,
|
||||
Message: e.Error(),
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ func (e errUnsupportedMediaType) Status() metav1.Status {
|
||||
return metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: http.StatusUnsupportedMediaType,
|
||||
Reason: metav1.StatusReason("UnsupportedMediaType"),
|
||||
Reason: metav1.StatusReasonUnsupportedMediaType,
|
||||
Message: e.Error(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user