paket/libpaket/src/lib.rs
2024-08-18 18:03:15 +02:00

68 lines
No EOL
1.6 KiB
Rust

mod www;
pub use www::WebClient;
pub mod login;
pub use login::OpenIdClient;
pub mod stammdaten;
pub use stammdaten::StammdatenClient;
mod common;
#[macro_use]
mod utils;
pub mod constants;
#[cfg(feature = "locker_base")]
pub mod locker;
#[cfg(feature = "advices")]
pub mod advices;
#[cfg(feature = "advices")]
pub use advices::AdviceClient;
/*#[cfg(test)]
pub(crate) mod private;*/
use thiserror::Error;
#[derive(Error, Debug, PartialEq)]
pub enum LibraryError {
#[error("network error: unable to fetch resource")]
NetworkFetch,
#[error("invalid credentials, unauthorized")]
Unauthorized,
#[error("invalid argument: {0}")]
InvalidArgument(String),
#[error("internal error, unable to decode: {0}")]
DecodeError(String),
#[error("upstream api was changed. not continuing")]
APIChange,
#[error("upstream api was changed. this method is deprecated")]
Deprecated,
}
pub type LibraryResult<T> = Result<T, LibraryError>;
impl From<reqwest::Error> for LibraryError {
fn from(item: reqwest::Error) -> Self {
if item.is_timeout() || item.is_request() || item.is_connect() || item.is_decode() {
Self::NetworkFetch
} else {
panic!("FIXME: unknown reqwest error kind: {:?}", item)
}
}
}
impl From<common::APIError> for LibraryError {
fn from(value: common::APIError) -> Self {
match value.error {
common::APIErrorType::InvalidGrant => Self::Unauthorized
}
}
}
impl From<serde_json::Error> for LibraryError {
fn from(value: serde_json::Error) -> Self {
Self::DecodeError(value.to_string())
}
}