use bytes::Bytes;
use http::response::Parts;
#[derive(Debug, Clone)]
pub struct ResponseExt<B = Bytes> {
pub response_parts: Parts,
pub body: B,
}
impl ResponseExt {
#[cfg(feature = "feat-response-ext-json")]
pub fn json<T>(self) -> Result<ResponseExt<T>, Self>
where
T: for<'a> serde::Deserialize<'a>,
{
match serde_json::from_slice(&self.body) {
Ok(body) => Ok(ResponseExt {
response_parts: self.response_parts,
body,
}),
Err(e) => {
#[cfg(feature = "feat-tracing")]
tracing::error!("Failed to parse JSON: {e:?}");
Err(self)
}
}
}
}