From 32d4c0fd80ff6421c3b83b04a9af8500b30363e4 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 12 Dec 2023 13:32:57 +0100 Subject: [PATCH] crates-io: Add support for other 2xx HTTP status codes Replying with `201 Created` of `202 Accepted` should not result in showing errors. --- crates/crates-io/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/crates-io/lib.rs b/crates/crates-io/lib.rs index b2a42378e1d..468900e55c1 100644 --- a/crates/crates-io/lib.rs +++ b/crates/crates-io/lib.rs @@ -436,7 +436,8 @@ impl Registry { .map(|s| s.errors.into_iter().map(|s| s.detail).collect::>()); match (self.handle.response_code()?, errors) { - (0, None) | (200, None) => Ok(body), + (0, None) => Ok(body), + (code, None) if is_success(code) => Ok(body), (code, Some(errors)) => Err(Error::Api { code, headers, @@ -451,8 +452,12 @@ impl Registry { } } +fn is_success(code: u32) -> bool { + code >= 200 && code < 300 +} + fn status(code: u32) -> String { - if code == 200 { + if is_success(code) { String::new() } else { let reason = reason(code);