uda_connector/
error.rs

1use std::fmt::Debug;
2use log::error;
3use crate::error::UdaError::MalformedSelector;
4use scraper::error::SelectorErrorKind;
5use thiserror::Error;
6
7#[derive(Debug, Error)]
8pub enum UdaError {
9    #[error("The connection to UDA has failed.")]
10    ConnectionFailed,
11    #[error("The page content couldn't be read.")]
12    CantReadPageContent,
13    #[error("The organisation memberships is inaccessible.")]
14    OrganizationMembershipsAccessFailed,
15    #[error("Missing permissions to read the page")]
16    LackOfPermissions,
17    #[error("Wrong credentials to log into UDA")]
18    WrongCredentials,
19    #[error("Provided selector is malformed [selector: {0}]")]
20    MalformedSelector(String),
21    #[error("The member can't be marked as confirmed [id: {0}]")]
22    MemberConfirmationFailed(u16),
23    #[error("The exported XLS file is malformed")]
24    MalformedXlsFile,
25}
26
27impl From<SelectorErrorKind<'_>> for UdaError {
28    fn from(value: SelectorErrorKind<'_>) -> Self {
29        MalformedSelector(value.to_string())
30    }
31}
32
33pub fn log_error_and_return<E: Debug, T>(value_to_return: T) -> impl FnOnce(E) -> T {
34    |e| {
35        error!("{e:#?}");
36        value_to_return
37    }
38}
39
40pub fn log_message_and_return<E: Debug, T>(
41    message: &str,
42    value_to_return: T,
43) -> impl FnOnce(E) -> T {
44    move |e| {
45        error!("{message}\n{e:#?}");
46        value_to_return
47    }
48}