aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2022-11-01 11:18:22 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2022-11-01 11:18:22 +0100
commit0fee82d284396b2d2354ddb494dd27abddfbad45 (patch)
treeb384db7f0473553d6309a668b90816b6c39ebfbb /src/error.rs
parentcb6e70690f6a1daa06c59ced9695437dc6a10ef3 (diff)
move error module to single file
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
new file mode 100644
index 0000000..b8a8c16
--- /dev/null
+++ b/src/error.rs
@@ -0,0 +1,63 @@
+use std::fmt;
+
+/// The Errors that may occur around Clients.
+#[derive(Debug)]
+pub enum Error {
+ ParseUrl(url::ParseError),
+ Reqwest(reqwest::Error),
+ XmlRpc(xmlrpc::Error),
+ Inexistent(String),
+ Type(String, String, xmlrpc::Value),
+ BadResponse(xmlrpc::Value),
+ BadStatus(Vec<i32>, i32),
+ BadVariant(String, String),
+}
+
+impl std::error::Error for Error {}
+
+impl fmt::Display for Error {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Error::ParseUrl(err) => write!(fmt, "can't parse Url: {}", err),
+ Error::Reqwest(err) => write!(fmt, "reqwest error: {}", err),
+ Error::XmlRpc(err) => write!(fmt, "xmlrpc error: {}", err),
+ Error::Inexistent(what) => {
+ write!(fmt, "parameter {} does not exist", what)
+ }
+ Error::Type(what, exp, got) => {
+ write!(
+ fmt,
+ "parameter {what} is of wrong type {got:?} (expected: {exp})"
+ )
+ }
+ Error::BadResponse(resp) => write!(fmt, "bad response: {:?}", resp),
+ Error::BadStatus(expected, got) => {
+ write!(fmt, "bad status {} (expected: {:?}", got, expected)
+ }
+ Error::BadVariant(ename, var) => {
+ write!(fmt, "{} is not a valid enum variant for {}", var, ename)
+ }
+ }
+ }
+}
+
+impl From<url::ParseError> for Error {
+ fn from(err: url::ParseError) -> Self {
+ Self::ParseUrl(err)
+ }
+}
+
+impl From<reqwest::Error> for Error {
+ fn from(err: reqwest::Error) -> Self {
+ Self::Reqwest(err)
+ }
+}
+
+impl From<xmlrpc::Error> for Error {
+ fn from(err: xmlrpc::Error) -> Self {
+ Self::XmlRpc(err)
+ }
+}
+
+/// A `Result` alias where the `Err` case is `inwx::Error`.
+pub type Result<T> = std::result::Result<T, Error>;