vatsim_api/error.rs
1//! Error types shared across the crate.
2//!
3//! [`ParseError`] is always available for type-conversion and CSV-parsing
4//! failures. [`ClientError`] is gated behind the `client` feature and wraps
5//! HTTP and parse errors from [`crate::client::VatsimClient`] methods.
6
7use thiserror::Error;
8
9/// Errors from parsing VATSIM types or CSV data.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum ParseError {
13 /// An unrecognized string or integer value for a known type (e.g. facility,
14 /// rating).
15 #[error("unknown {kind}: {value}")]
16 UnknownValue {
17 /// The kind of value that failed to parse, e.g. `"facility"`.
18 kind: &'static str,
19 /// The unrecognized value, rendered as a string.
20 value: String,
21 },
22 /// A malformed line in the slurper CSV response.
23 #[error("invalid slurper CSV at line {line}: {reason}")]
24 InvalidSlurperCsv {
25 /// One-based line number within the response body.
26 line: usize,
27 /// What made the line unparseable.
28 reason: String,
29 },
30}
31
32/// Errors from [`VatsimClient`](crate::client::VatsimClient) operations.
33#[cfg(feature = "client")]
34#[derive(Debug, Error)]
35#[non_exhaustive]
36pub enum ClientError {
37 /// An HTTP-level failure (connection, timeout, non-success status code).
38 #[error("HTTP error: {0}")]
39 Http(#[from] reqwest::Error),
40
41 /// The response body could not be deserialized or parsed.
42 #[error("failed to parse response: {0}")]
43 Parse(#[from] ParseError),
44
45 /// The [VATSIM status endpoint](https://status.vatsim.net/status.json)
46 /// returned an empty list of data URLs.
47 #[error("status endpoint returned no usable data URLs")]
48 NoDataUrls,
49}