Skip to content

Commit 32d4c0f

Browse files
committed
crates-io: Add support for other 2xx HTTP status codes
Replying with `201 Created` of `202 Accepted` should not result in showing errors.
1 parent 623b788 commit 32d4c0f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/crates-io/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ impl Registry {
436436
.map(|s| s.errors.into_iter().map(|s| s.detail).collect::<Vec<_>>());
437437

438438
match (self.handle.response_code()?, errors) {
439-
(0, None) | (200, None) => Ok(body),
439+
(0, None) => Ok(body),
440+
(code, None) if is_success(code) => Ok(body),
440441
(code, Some(errors)) => Err(Error::Api {
441442
code,
442443
headers,
@@ -451,8 +452,12 @@ impl Registry {
451452
}
452453
}
453454

455+
fn is_success(code: u32) -> bool {
456+
code >= 200 && code < 300
457+
}
458+
454459
fn status(code: u32) -> String {
455-
if code == 200 {
460+
if is_success(code) {
456461
String::new()
457462
} else {
458463
let reason = reason(code);

0 commit comments

Comments
 (0)