Skip to content

Commit 4f62153

Browse files
fidencioShadowCurse
authored andcommitted
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 <[email protected]>
1 parent e854e50 commit 4f62153

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/response.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub enum StatusCode {
3030
MethodNotAllowed,
3131
/// 413, Payload Too Large
3232
PayloadTooLarge,
33+
/// 429, Too Many Requests
34+
TooManyRequests,
3335
/// 500, Internal Server Error
3436
InternalServerError,
3537
/// 501, Not Implemented
@@ -50,6 +52,7 @@ impl StatusCode {
5052
Self::NotFound => b"404",
5153
Self::MethodNotAllowed => b"405",
5254
Self::PayloadTooLarge => b"413",
55+
Self::TooManyRequests => b"429",
5356
Self::InternalServerError => b"500",
5457
Self::NotImplemented => b"501",
5558
Self::ServiceUnavailable => b"503",
@@ -448,6 +451,7 @@ mod tests {
448451
assert_eq!(StatusCode::NotFound.raw(), b"404");
449452
assert_eq!(StatusCode::MethodNotAllowed.raw(), b"405");
450453
assert_eq!(StatusCode::PayloadTooLarge.raw(), b"413");
454+
assert_eq!(StatusCode::TooManyRequests.raw(), b"429");
451455
assert_eq!(StatusCode::InternalServerError.raw(), b"500");
452456
assert_eq!(StatusCode::NotImplemented.raw(), b"501");
453457
assert_eq!(StatusCode::ServiceUnavailable.raw(), b"503");

0 commit comments

Comments
 (0)