mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-03 10:33:49 +00:00
Better WrappedReqwestError docs (#9251)
Document the hack with which we insert a hint message for offline cases.
This commit is contained in:
parent
c188b11b0a
commit
0913382aa5
1 changed files with 5 additions and 4 deletions
|
@ -322,8 +322,10 @@ impl Deref for WrappedReqwestError {
|
|||
impl Display for WrappedReqwestError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
if self.is_likely_offline() {
|
||||
// Insert an extra hint, we'll show the wrapped error through `source`
|
||||
f.write_str("Could not connect, are you offline?")
|
||||
} else {
|
||||
// Show the wrapped error
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
@ -332,11 +334,10 @@ impl Display for WrappedReqwestError {
|
|||
impl std::error::Error for WrappedReqwestError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
if self.is_likely_offline() {
|
||||
match &self.0 {
|
||||
reqwest_middleware::Error::Middleware(err) => Some(err.as_ref()),
|
||||
reqwest_middleware::Error::Reqwest(err) => Some(err),
|
||||
}
|
||||
// `Display` is inserting an extra message, so we need to show the wrapped error
|
||||
Some(&self.0)
|
||||
} else {
|
||||
// `Display` is showing the wrapped error, continue with its source
|
||||
self.0.source()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue