use tracing::{error, warn};
#[derive(Debug, thiserror::Error)]
pub enum TokenAuthError {
#[error("Authentication failed: Missing required {0} credentials")]
MissingCredentials(&'static str),
#[error("Token authentication failed: {0}")]
AuthenticationFailed(String),
#[error("Network error during authentication: {0}")]
NetworkError(#[from] reqwest::Error),
}
impl TokenAuthError {
pub(crate) fn log(&self) {
match self {
Self::MissingCredentials(field) => {
warn!(error = %self, field = %field, "Token authentication failed due to missing credentials");
}
Self::AuthenticationFailed(msg) => {
error!(error = %self, details = %msg, "Token authentication failed");
}
Self::NetworkError(e) => {
error!(error = %self, network_error = %e, "Token authentication failed due to network error");
}
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum FileUploadError {
#[error("File upload failed: Unable to read file - {0}")]
FileReadError(#[from] std::io::Error),
#[error("File upload failed: Network error - {0}")]
UploadError(#[from] reqwest::Error),
#[error("File upload failed: Invalid content type provided")]
InvalidContentType,
#[error("File upload failed: Server responded with unexpected status code {0}")]
UnexpectedStatusCode(reqwest::StatusCode),
#[error("File upload failed: Invalid URL provided - {0}")]
InvalidURL(String),
}
impl FileUploadError {
pub(crate) fn log(&self) {
match self {
Self::FileReadError(e) => {
error!(error = %self, io_error = %e, "File upload failed due to file read error");
}
Self::UploadError(e) => {
error!(error = %self, network_error = %e, "File upload failed due to network error");
}
Self::InvalidContentType => {
warn!(error = %self, "File upload failed due to invalid content type");
}
Self::UnexpectedStatusCode(status) => {
error!(error = %self, status_code = %status, "File upload failed with unexpected status code");
}
Self::InvalidURL(url) => {
warn!(error = %self, url = %url, "File upload failed due to invalid URL");
}
}
}
}