Skip to content

Commit 03821dd

Browse files
committed
Fix ureq 3 migration: handle 404 in Error::StatusCode
In ureq 3, HTTP error statuses are returned as Error::StatusCode(u16) from call(), not as successful responses. The 404 check was placed after call() but 404 was caught by map_err first, producing ExternalFetchFailed instead of CrateNotFound.
1 parent 5df83b2 commit 03821dd

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

src/external.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,19 @@ fn query_crates_io(name: &str) -> Result<CratesIoResponse> {
190190
let url = format!("https://crates.io/api/v1/crates/{name}");
191191
let agent = build_http_agent();
192192

193-
let mut response = agent
194-
.get(&url)
195-
.call()
196-
.map_err(|e| GroxError::ExternalFetchFailed {
197-
name: name.to_string(),
198-
details: format!("crates.io API error: {e}"),
199-
})?;
200-
201-
if response.status() == 404 {
202-
return Err(GroxError::CrateNotFound {
203-
name: name.to_string(),
204-
suggestions: vec![],
205-
});
206-
}
193+
let mut response = agent.get(&url).call().map_err(|e| {
194+
if matches!(e, ureq::Error::StatusCode(404)) {
195+
GroxError::CrateNotFound {
196+
name: name.to_string(),
197+
suggestions: vec![],
198+
}
199+
} else {
200+
GroxError::ExternalFetchFailed {
201+
name: name.to_string(),
202+
details: format!("crates.io API error: {e}"),
203+
}
204+
}
205+
})?;
207206

208207
response
209208
.body_mut()

0 commit comments

Comments
 (0)