Skip to main content

max / supernote-push

1.0 KB · 33 lines History Blame Raw
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 /// `Status` is not produced here. ureq 3's `Error::StatusCode` carries only
17 /// the code, never the response, so the agent turns off
18 /// `http_status_as_error` and `browse` checks the status while it still
19 /// holds the body. See `browse::status_error`.
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 // e is consumed into the stringified error variant.
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