1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug)]
10#[non_exhaustive]
11pub enum Error {
12 Status {
14 status: u16,
16 body: String,
18 },
19 NoQueryResult,
21 NoEquivalentResource,
23 TooManyRedirects,
25 Invalid(String),
27 #[cfg(feature = "client")]
29 Transport(reqwest::Error),
30 #[cfg(feature = "client")]
32 Json(serde_json::Error),
33}
34
35impl fmt::Display for Error {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Error::Status { status, .. } => write!(f, "server returned status {status}"),
39 Error::NoQueryResult => f.write_str("response has no query result location"),
40 Error::NoEquivalentResource => {
41 f.write_str("response has no equivalent resource location")
42 }
43 Error::TooManyRedirects => f.write_str("too many redirects"),
44 Error::Invalid(msg) => write!(f, "invalid input: {msg}"),
45 #[cfg(feature = "client")]
46 Error::Transport(err) => write!(f, "transport error: {err}"),
47 #[cfg(feature = "client")]
48 Error::Json(err) => write!(f, "json error: {err}"),
49 }
50 }
51}
52
53impl std::error::Error for Error {
54 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
55 match self {
56 #[cfg(feature = "client")]
57 Error::Transport(err) => Some(err),
58 #[cfg(feature = "client")]
59 Error::Json(err) => Some(err),
60 _ => None,
61 }
62 }
63}
64
65#[cfg(feature = "client")]
66impl From<reqwest::Error> for Error {
67 fn from(err: reqwest::Error) -> Self {
68 Error::Transport(err)
69 }
70}
71
72#[cfg(feature = "client")]
73impl From<serde_json::Error> for Error {
74 fn from(err: serde_json::Error) -> Self {
75 Error::Json(err)
76 }
77}