stac_api/
error.rs

1use crate::Search;
2use chrono::{DateTime, FixedOffset};
3use serde_json::{Map, Value};
4use thiserror::Error;
5
6/// Crate-specific error enum.
7#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum Error {
10    /// Queries cannot be converted to strings.
11    #[error("cannot convert queries to strings")]
12    CannotConvertQueryToString(Map<String, Value>),
13
14    /// CQL2 JSON cannot (currently) be converted to strings.
15    ///
16    /// TODO support conversion
17    #[error("cannot convert cql2-json to strings")]
18    CannotConvertCql2JsonToString(Map<String, Value>),
19
20    /// [chrono::ParseError]
21    #[error(transparent)]
22    ChronoParse(#[from] chrono::ParseError),
23
24    /// [cql2::Error]
25    #[error(transparent)]
26    Cql2(#[from] Box<cql2::Error>),
27
28    /// [geojson::Error]
29    #[error(transparent)]
30    GeoJson(#[from] Box<geojson::Error>),
31
32    /// An empty datetime interval.
33    #[error("empty datetime interval")]
34    EmptyDatetimeInterval,
35
36    /// Some functionality requires a certain optional feature to be enabled.
37    #[error("feature not enabled: {0}")]
38    FeatureNotEnabled(&'static str),
39
40    /// Invalid bounding box.
41    #[error("invalid bbox ({0:?}): {1}")]
42    InvalidBbox(Vec<f64>, &'static str),
43
44    /// [http::header::InvalidHeaderName]
45    #[error(transparent)]
46    #[cfg(feature = "client")]
47    InvalidHeaderName(#[from] http::header::InvalidHeaderName),
48
49    /// [http::header::InvalidHeaderValue]
50    #[error(transparent)]
51    #[cfg(feature = "client")]
52    InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
53
54    /// [http::method::InvalidMethod]
55    #[error(transparent)]
56    #[cfg(feature = "client")]
57    InvalidMethod(#[from] http::method::InvalidMethod),
58
59    /// [std::io::Error]
60    #[error(transparent)]
61    #[cfg(feature = "client")]
62    Io(#[from] std::io::Error),
63
64    /// [tokio::task::JoinError]
65    #[error(transparent)]
66    #[cfg(feature = "client")]
67    Join(#[from] tokio::task::JoinError),
68
69    /// [std::num::ParseIntError]
70    #[error(transparent)]
71    ParseIntError(#[from] std::num::ParseIntError),
72
73    /// [std::num::ParseFloatError]
74    #[error(transparent)]
75    ParseFloatError(#[from] std::num::ParseFloatError),
76
77    /// [reqwest::Error]
78    #[error(transparent)]
79    #[cfg(feature = "client")]
80    Reqwest(#[from] reqwest::Error),
81
82    /// A search has both bbox and intersects.
83    #[error("search has bbox and intersects")]
84    SearchHasBboxAndIntersects(Box<Search>),
85
86    /// [serde_json::Error]
87    #[error(transparent)]
88    SerdeJson(#[from] serde_json::Error),
89
90    /// [serde_urlencoded::ser::Error]
91    #[error(transparent)]
92    SerdeUrlencodedSer(#[from] serde_urlencoded::ser::Error),
93
94    /// [stac::Error]
95    #[error(transparent)]
96    Stac(#[from] stac::Error),
97
98    /// The start time is after the end time.
99    #[error("start ({0}) is after end ({1})")]
100    StartIsAfterEnd(DateTime<FixedOffset>, DateTime<FixedOffset>),
101
102    /// [std::num::TryFromIntError]
103    #[error(transparent)]
104    TryFromInt(#[from] std::num::TryFromIntError),
105
106    /// [url::ParseError]
107    #[error(transparent)]
108    UrlParse(#[from] url::ParseError),
109
110    /// This functionality is not yet implemented.
111    #[error("this functionality is not yet implemented: {0}")]
112    Unimplemented(&'static str),
113}