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:
Fabiano Fidêncio
2025-04-25 20:21:18 +02:00
committed by Bo Chen
parent 87007a288f
commit d0225fe68f
3 changed files with 38 additions and 2 deletions

View File

@@ -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),
}
}