use serde::Deserialize;
use serde_json::Value;
use std::fmt;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Http(#[from] reqwest::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error("Recieved error: {0}")]
KSQLStream(String),
#[error("Received final message: {0}")]
FinalMessage(String),
#[error("{0}")]
KSQL(KsqlDBError),
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all(serialize = "snake_case", deserialize = "camelCase"))]
pub struct KsqlDBError {
#[serde(rename = "@type")]
pub response_type: String,
pub statement_text: Option<String>,
#[serde(rename = "error_code")] pub error_code: Option<u32>,
pub message: Option<String>,
pub entities: Option<Vec<Value>>,
}
impl fmt::Display for KsqlDBError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Received error from KSQL DB: response type '{}', with error code [{}] and message: '{}'",
self.response_type,
self.error_code.unwrap_or_default(),
self.message.clone().unwrap_or_default()
)
}
}