response: Add "TooManyRequests" status code

The addition of the "TooManyRequests" status code is in order to notify
users when an operation is still pending, and this seems to be the best
fit we can have for now.

On the Cloud Hypervisor side we'll use it, for instance, for the case
when a caller tries to offline a vCPU but the previous offline operation
is still pending, leaving at least a chance for the caller to analyse
the error and decide whether they want to retry the operation or not.

TooManyRequests: 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 12:31:21 +02:00
committed by ShadowCurse
parent e854e50bc0
commit 4f621532e8

View File

@@ -30,6 +30,8 @@ pub enum StatusCode {
MethodNotAllowed,
/// 413, Payload Too Large
PayloadTooLarge,
/// 429, Too Many Requests
TooManyRequests,
/// 500, Internal Server Error
InternalServerError,
/// 501, Not Implemented
@@ -50,6 +52,7 @@ impl StatusCode {
Self::NotFound => b"404",
Self::MethodNotAllowed => b"405",
Self::PayloadTooLarge => b"413",
Self::TooManyRequests => b"429",
Self::InternalServerError => b"500",
Self::NotImplemented => b"501",
Self::ServiceUnavailable => b"503",
@@ -448,6 +451,7 @@ mod tests {
assert_eq!(StatusCode::NotFound.raw(), b"404");
assert_eq!(StatusCode::MethodNotAllowed.raw(), b"405");
assert_eq!(StatusCode::PayloadTooLarge.raw(), b"413");
assert_eq!(StatusCode::TooManyRequests.raw(), b"429");
assert_eq!(StatusCode::InternalServerError.raw(), b"500");
assert_eq!(StatusCode::NotImplemented.raw(), b"501");
assert_eq!(StatusCode::ServiceUnavailable.raw(), b"503");