#[derive(Debug, thiserror::Error)]
#[error("failed to deserialize a response from:\n{uri}\n{inner}")]
pub struct DeserializeError {
uri: url::Url,
bytes: Vec<u8>,
#[source]
inner: serde_path_to_error::Error<serde_json::Error>,
}
#[derive(Debug, thiserror::Error)]
#[error("received unsuccessful status code {status} from:\n{uri}")]
pub struct ResponseError {
uri: url::Url,
bytes: Vec<u8>,
status: http::StatusCode,
}
macro_rules! impl_field_accessors {
($implementor:ident) => {
impl $implementor {
pub fn uri(&self) -> &url::Url {
&self.uri
}
pub fn bytes(&self) -> &[u8] {
&self.bytes
}
pub fn into_uri(self) -> url::Url {
self.uri
}
pub fn into_bytes(self) -> Vec<u8> {
self.bytes
}
pub fn into_uri_bytes(self) -> (url::Url, Vec<u8>) {
(self.uri, self.bytes)
}
}
};
}
impl_field_accessors!(DeserializeError);
impl_field_accessors!(ResponseError);
impl DeserializeError {
#[doc(hidden)]
pub fn __new(
uri: url::Url,
bytes: Vec<u8>,
error: serde_path_to_error::Error<serde_json::Error>,
) -> Self {
Self {
uri,
bytes,
inner: error,
}
}
pub fn path(&self) -> &serde_path_to_error::Path {
self.inner.path()
}
pub fn inner(&self) -> &serde_json::Error {
self.inner.inner()
}
pub fn into_inner(self) -> serde_json::Error {
self.inner.into_inner()
}
}
impl ResponseError {
#[doc(hidden)]
pub fn __new(uri: url::Url, bytes: Vec<u8>, status: http::StatusCode) -> Self {
Self { uri, bytes, status }
}
pub fn status_code(&self) -> http::StatusCode {
self.status
}
}