mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +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
|
reason = metav1.StatusReasonForbidden
|
||||||
// the server message has details about who is trying to perform what action. Keep its message.
|
// the server message has details about who is trying to perform what action. Keep its message.
|
||||||
message = serverMessage
|
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:
|
case http.StatusMethodNotAllowed:
|
||||||
reason = metav1.StatusReasonMethodNotAllowed
|
reason = metav1.StatusReasonMethodNotAllowed
|
||||||
message = "the server does not allow this method on the requested resource"
|
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
|
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
|
// 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.
|
// be performed because it is not supported by the server.
|
||||||
func IsMethodNotSupported(err error) bool {
|
func IsMethodNotSupported(err error) bool {
|
||||||
|
@ -651,6 +651,18 @@ const (
|
|||||||
// can only be created. API calls that return MethodNotAllowed can never succeed.
|
// can only be created. API calls that return MethodNotAllowed can never succeed.
|
||||||
StatusReasonMethodNotAllowed StatusReason = "MethodNotAllowed"
|
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
|
// StatusReasonInternalError indicates that an internal error occurred, it is unexpected
|
||||||
// and the outcome of the call is unknown.
|
// and the outcome of the call is unknown.
|
||||||
// Details (optional):
|
// Details (optional):
|
||||||
|
@ -41,7 +41,7 @@ func (e errNotAcceptable) Status() metav1.Status {
|
|||||||
return metav1.Status{
|
return metav1.Status{
|
||||||
Status: metav1.StatusFailure,
|
Status: metav1.StatusFailure,
|
||||||
Code: http.StatusNotAcceptable,
|
Code: http.StatusNotAcceptable,
|
||||||
Reason: metav1.StatusReason("NotAcceptable"),
|
Reason: metav1.StatusReasonNotAcceptable,
|
||||||
Message: e.Error(),
|
Message: e.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (e errUnsupportedMediaType) Status() metav1.Status {
|
|||||||
return metav1.Status{
|
return metav1.Status{
|
||||||
Status: metav1.StatusFailure,
|
Status: metav1.StatusFailure,
|
||||||
Code: http.StatusUnsupportedMediaType,
|
Code: http.StatusUnsupportedMediaType,
|
||||||
Reason: metav1.StatusReason("UnsupportedMediaType"),
|
Reason: metav1.StatusReasonUnsupportedMediaType,
|
||||||
Message: e.Error(),
|
Message: e.Error(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user