#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ResponseBody {
Value(serde_json::Value),
Raw(Vec<u8>),
}
impl ResponseBody {
#[must_use]
pub const fn is_raw(&self) -> bool {
matches!(self, Self::Raw(_))
}
pub fn into_value(self) -> crate::error::Result<serde_json::Value> {
match self {
Self::Value(value) => Ok(value),
Self::Raw(bytes) => {
serde_json::from_slice(&bytes).map_err(|e| crate::error::FraiseQLError::Internal {
message: format!("a raw response body is not valid JSON: {e}"),
source: None,
})
},
}
}
pub fn into_bytes(self) -> serde_json::Result<Vec<u8>> {
match self {
Self::Value(value) => serde_json::to_vec(&value),
Self::Raw(bytes) => Ok(bytes),
}
}
}