mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: api: Be more specific on "Still pending remove vcpu" errors
Although the CPU manager gives us a quite descriptive error, on the application side (the part calling Cloud Hypervisor) we have absolutely no way to distinguish such error from any other error that may happen when resizing a VM. With this in mind, let's be more specific and return a TooManyRequests (429) error, allowing the caller to have a chance to decide whether they want to retry the operation or not. https://datatracker.ietf.org/doc/html/rfc6585#section-4 Signed-off-by: Fabiano Fidêncio <fidencio@northflank.com>
This commit is contained in:
committed by
Bo Chen
parent
87007a288f
commit
d0225fe68f
@@ -52,6 +52,9 @@ pub enum HttpError {
|
||||
/// Undefined endpoints
|
||||
NotFound,
|
||||
|
||||
/// Too many requests
|
||||
TooManyRequests,
|
||||
|
||||
/// Internal Server Error
|
||||
InternalServerError,
|
||||
|
||||
@@ -65,6 +68,7 @@ impl Display for HttpError {
|
||||
match self {
|
||||
BadRequest => write!(f, "Bad Request"),
|
||||
NotFound => write!(f, "Not Found"),
|
||||
TooManyRequests => write!(f, "Too Many Requests"),
|
||||
InternalServerError => write!(f, "Internal Server Error"),
|
||||
SerdeJsonDeserialize(serde_error) => write!(f, "{}", serde_error),
|
||||
ApiError(api_error) => write!(f, "{}", api_error),
|
||||
@@ -125,6 +129,7 @@ pub trait EndpointHandler {
|
||||
Err(e @ HttpError::SerdeJsonDeserialize(_)) => {
|
||||
error_response(e, StatusCode::BadRequest)
|
||||
}
|
||||
Err(e @ HttpError::TooManyRequests) => error_response(e, StatusCode::TooManyRequests),
|
||||
Err(e) => error_response(e, StatusCode::InternalServerError),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user