| 1 |
#[derive(Debug, thiserror::Error)] |
| 2 |
pub enum Error { |
| 3 |
#[error("HTTP request failed: {0}")] |
| 4 |
Http(String), |
| 5 |
#[error("device returned {status}: {body}")] |
| 6 |
Status { status: u16, body: String }, |
| 7 |
#[error("mDNS: {0}")] |
| 8 |
Mdns(String), |
| 9 |
#[error("I/O: {0}")] |
| 10 |
Io(#[from] std::io::Error), |
| 11 |
#[error("device unreachable — check Wi-Fi Transfer toggle")] |
| 12 |
Unreachable, |
| 13 |
} |
| 14 |
|
| 15 |
impl Error { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
pub(crate) fn from_http(e: ureq::Error) -> Self { |
| 21 |
match e { |
| 22 |
ureq::Error::Io(io) => Self::Io(io), |
| 23 |
other => Self::Http(other.to_string()), |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
#[allow(clippy::needless_pass_by_value)] |
| 29 |
pub(crate) fn from_mdns(e: mdns_sd::Error) -> Self { |
| 30 |
Self::Mdns(e.to_string()) |
| 31 |
} |
| 32 |
} |
| 33 |
|