use std::{env::VarError, string::FromUtf8Error};
use reqwest::header::InvalidHeaderValue;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("An error occurred when processing a request: {0}")]
ClientError(#[from] reqwest::Error),
#[error("Invalid configuration provided: {0}")]
InvalidConfiguration(#[from] InvalidHeaderValue),
#[error("Parsing error has occurred: {0}")]
ParsingError(String),
#[cfg(any(feature = "json", feature = "functions"))]
#[error("Failed to (de)serialize data: {0}")]
SerdeJsonError(#[from] serde_json::Error),
#[error("Failed to (de)serialize data: {0}")]
#[cfg(feature = "postcard")]
PostcardError(#[from] postcard::Error),
#[error("Failed to parse string from UTF-8: {0}")]
StringError(#[from] FromUtf8Error),
#[error("An error (type: {error_type}) occurred on the API backend: {message}")]
BackendError {
message: String,
error_type: String,
},
#[error("Error happened during an IO operation: {0}")]
IOError(#[from] tokio::io::Error),
#[error("Error while trying to access an environment variable: {0}")]
VarError(#[from] VarError),
}