Skip to content

Commit

Permalink
Auto merge of #13158 - Turbo87:crates-io-status-codes, r=epage
Browse files Browse the repository at this point in the history
crates-io: Add support for other 2xx HTTP status codes

Replying with `201 Created` of `202 Accepted` should not result in showing errors.

Related:

- #3995
- #6771
  • Loading branch information
bors committed Dec 12, 2023
2 parents 5dc5118 + 32d4c0f commit 1aa9df1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ impl Registry {
.map(|s| s.errors.into_iter().map(|s| s.detail).collect::<Vec<_>>());

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,
Expand All @@ -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);
Expand Down

0 comments on commit 1aa9df1

Please sign in to comment.