use std::time::SystemTimeError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Invalid URL: {0}")]
InvalidUrl(String),
#[error("Timeout while trying to connect to Uptime Kuma server")]
ConnectionTimeout,
#[error("Timeout while trying to call '{0}'.")]
CallTimeout(String),
#[error("Tried to access Uptime Kuma state before it was ready...")]
NotReady,
#[error("The server rejected the login: {0}")]
LoginError(String),
#[error("It looks like the server is expecting a username/password, but none was provided")]
NotAuthenticated,
#[error("MFA enabled, but no token/secret was provided")]
TokenRequired,
#[error("Connection to Uptime Kuma was lost")]
Disconnected,
#[error("Received invalid response from server (missing key '{1}'): {0:?}")]
InvalidResponse(Vec<serde_json::Value>, String),
#[error("Server responded with an error: {0}")]
ServerError(String),
#[error("Received unsupported message from server")]
UnsupportedResponse,
#[error("Error during communication: {0}")]
CommunicationError(String),
#[error("Encountered errors trying to validate '{0}': {1:?}")]
ValidationError(String, Vec<String>),
#[error("No {0} with ID {1} could be found")]
IdNotFound(String, i32),
#[error("No {0} with slug {1} could be found")]
SlugNotFound(String, String),
#[error("Unable to load custom tls cert {0}: {1}")]
InvalidTlsCert(String, String),
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error(transparent)]
Totp(#[from] TotpError),
#[error(transparent)]
InvalidReference(#[from] InvalidReferenceError),
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum TotpError {
#[error(transparent)]
TotpUrlError(#[from] totp_rs::TotpUrlError),
#[error(transparent)]
SecretParseError(#[from] totp_rs::SecretParseError),
#[error(transparent)]
Rfc6238Error(#[from] totp_rs::Rfc6238Error),
#[error(transparent)]
SystemTimeError(#[from] SystemTimeError),
}
pub type TotpResult<T> = std::result::Result<T, TotpError>;
#[derive(Error, Debug)]
pub enum InvalidReferenceError {
#[error("Unknown parent monitor ID {0}")]
InvalidParent(String),
#[error("Unknown notification ID {0}")]
InvalidNotification(String),
#[error("Unknown docker host ID {0}")]
InvalidDockerHost(String),
}
impl From<Error> for Vec<Error> {
fn from(err: Error) -> Self {
vec![err]
}
}