Skip to main content

scribe_client/
error.rs

1use thiserror::Error;
2
3/// Every variant that can originate from a server response carries a
4/// `message: String` — the server's own human-readable sentence, passed
5/// through unchanged. Never build user-facing text from a status code,
6/// error code, or the internals of `reqwest`/`serde_json` here; those
7/// stay out of `Display` (available via `.source()` for logging only).
8#[derive(Debug, Error)]
9pub enum ScribeError {
10    #[error("Couldn't connect to Scribe. Check your connection and try again.")]
11    Http(#[from] reqwest::Error),
12    #[error("Something went wrong. Please try again.")]
13    Decode(#[from] serde_json::Error),
14    #[error("Something went wrong. Please try again.")]
15    Url(#[from] url::ParseError),
16    #[error("{message}")]
17    Api {
18        status: u16,
19        code: String,
20        message: String,
21    },
22    #[error("{message}")]
23    InvalidGrant { message: String },
24    #[error("{message}")]
25    ConversionNotComplete { message: String },
26    #[error("{message}")]
27    NotFound { message: String },
28    #[error("{message}")]
29    Forbidden { message: String },
30    #[error("{message}")]
31    NotTrashed { message: String },
32    /// The document channel's WebSocket connection failed or was closed
33    /// unexpectedly. Boxed: `tungstenite::Error` is large enough on its own
34    /// to blow up the size of every other, far more common, error path.
35    #[error("Couldn't connect to Scribe. Check your connection and try again.")]
36    WebSocket(#[from] Box<tokio_tungstenite::tungstenite::Error>),
37    #[error("channel closed before a reply arrived")]
38    ChannelClosed,
39    // These three only ever arise via the WebSocket channel today (see
40    // channel.rs) — the server's channel error frames don't carry a
41    // `message` field yet, so these keep the same friendly text that was
42    // already hardcoded here before, just reshaped consistently with
43    // everything else.
44    #[error("{message}")]
45    ConversionInProgress { message: String },
46    #[error("{message}")]
47    RateLimited { message: String },
48    #[error("{message}")]
49    NeedsPurchase {
50        message: String,
51        purchase_url: String,
52    },
53    /// The document is a password-protected file that hasn't been unlocked
54    /// yet. Prompt for the password and retry the same call with it.
55    #[error("{message}")]
56    PasswordRequired { message: String },
57    #[error("{message}")]
58    Channel { message: String },
59}