awaur/endpoints/
errors.rs1#[derive(Debug, thiserror::Error)]
6#[error("failed to deserialize a response from:\n{uri}\n{inner}")]
7pub struct DeserializeError {
8 uri: url::Url,
9 bytes: Vec<u8>,
10 #[source]
11 inner: serde_path_to_error::Error<serde_json::Error>,
12}
13
14#[derive(Debug, thiserror::Error)]
18#[error("received unsuccessful status code {status} from:\n{uri}")]
19pub struct ResponseError {
20 uri: url::Url,
21 bytes: Vec<u8>,
22 status: http::StatusCode,
23}
24
25macro_rules! impl_field_accessors {
26 ($implementor:ident) => {
27 impl $implementor {
28 pub fn uri(&self) -> &url::Url {
30 &self.uri
31 }
32
33 pub fn bytes(&self) -> &[u8] {
35 &self.bytes
36 }
37
38 pub fn into_uri(self) -> url::Url {
40 self.uri
41 }
42
43 pub fn into_bytes(self) -> Vec<u8> {
45 self.bytes
46 }
47
48 pub fn into_uri_bytes(self) -> (url::Url, Vec<u8>) {
51 (self.uri, self.bytes)
52 }
53 }
54 };
55}
56
57impl_field_accessors!(DeserializeError);
58impl_field_accessors!(ResponseError);
59
60impl DeserializeError {
61 #[doc(hidden)]
62 pub fn __new(
63 uri: url::Url,
64 bytes: Vec<u8>,
65 error: serde_path_to_error::Error<serde_json::Error>,
66 ) -> Self {
67 Self {
68 uri,
69 bytes,
70 inner: error,
71 }
72 }
73
74 pub fn path(&self) -> &serde_path_to_error::Path {
78 self.inner.path()
79 }
80
81 pub fn inner(&self) -> &serde_json::Error {
83 self.inner.inner()
84 }
85
86 pub fn into_inner(self) -> serde_json::Error {
88 self.inner.into_inner()
89 }
90}
91
92impl ResponseError {
93 #[doc(hidden)]
94 pub fn __new(uri: url::Url, bytes: Vec<u8>, status: http::StatusCode) -> Self {
95 Self { uri, bytes, status }
96 }
97
98 pub fn status_code(&self) -> http::StatusCode {
100 self.status
101 }
102}