use reqwest::{self, StatusCode};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ClientError {
#[error("An IO error occurred: {0}")]
IoError(#[from] std::io::Error),
#[error("The provided request method is invalid")]
InvalidRequestMethod,
#[error("The provided event type is invalid")]
InvalidEventType,
#[error("The provided API token is invalid")]
APITokenInvalid,
#[error("Pinging the DB failed")]
PingFailed,
#[error("The request failed with error: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("The URL is invalid: {0}")]
URLParseError(#[from] url::ParseError),
#[error("The JSON serialization failed: {0}")]
SerdeJsonError(#[from] serde_json::Error),
#[error("The DB returned an error in the response: {0}")]
DBError(String),
#[error("The DB returned an error: {0}")]
DBApiError(StatusCode, String),
#[error("The passed jsonschema is invalid")]
JsonSchemaError,
#[cfg(feature = "cloudevents")]
#[error("The CloudEvents message is invalid: {0}")]
CloudeventsMessageError(#[from] cloudevents::message::Error),
#[error("The DB returned an invalid response type: {0}")]
InvalidResponseType(String),
#[error("Server must be EventSourcingDB")]
InvalidServerHeader,
}
#[cfg(feature = "testcontainer")]
#[derive(Debug, Error)]
pub enum ContainerError {
#[error("Testcontainers error: {0}")]
TestcontainersError(#[from] testcontainers::TestcontainersError),
#[error("URL parsing error: {0}")]
URLParseError(#[from] url::ParseError),
#[error("Error encoding the signing key: {0}")]
SigningKeyEncodingError(#[from] ed25519_dalek::pkcs8::Error),
}
#[derive(Debug, thiserror::Error)]
pub enum EventError {
#[cfg(feature = "cloudevents")]
#[error("The passed cloudevent is invalid")]
InvalidCloudevent,
#[error("Hash verification failed")]
HashVerificationFailed {
expected: String,
actual: String,
},
#[error("Serde error: {0}")]
SerdeError(#[from] serde_json::Error),
#[error("Signature is missing for the event")]
MissingSignature,
#[error("Signature is malformed")]
MalformedSignature,
#[error("A problem with signature verification occurred: {0}")]
SignatureError(#[from] ed25519_dalek::SignatureError),
}