1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use alloc::borrow::Cow;
/// Error type for payload construction and relayer client operations.
#[derive(Debug, thiserror::Error)]
pub enum PolyrelError {
/// Validation failed before a payload or request could be constructed.
#[error("validation error: {0}")]
Validation(Cow<'static, str>),
/// A [`crate::NonEmptyCalls`] collection was constructed from an empty vector.
#[error("empty calls error")]
EmptyCalls,
/// A signature was malformed or incompatible with the expected format.
#[error("invalid signature: {0}")]
InvalidSignature(Cow<'static, str>),
/// Serialization into a JSON or wire-format representation failed.
#[error("serialization error: {0}")]
Serialize(Cow<'static, str>),
/// Deserialization or DTO-to-domain conversion failed.
#[error("deserialization error: {0}")]
Deserialize(Cow<'static, str>),
/// The underlying HTTP client returned a transport-level error.
#[error("http error: {0}")]
Http(Cow<'static, str>),
/// The relayer returned a non-success HTTP response.
#[error("api error {status}: {body}")]
Api {
/// HTTP status code returned by the relayer.
status: u16,
/// Response body returned by the relayer.
body: Cow<'static, str>,
},
}
impl PolyrelError {
/// Creates a [`Self::Validation`] error.
pub fn validation<E>(msg: E) -> Self
where
Cow<'static, str>: From<E>,
{
Self::Validation(Cow::from(msg))
}
/// Creates an [`Self::InvalidSignature`] error.
pub fn invalid_signature<E>(msg: E) -> Self
where
Cow<'static, str>: From<E>,
{
Self::InvalidSignature(Cow::from(msg))
}
/// Creates a [`Self::Serialize`] error.
pub fn serialize<E>(msg: E) -> Self
where
Cow<'static, str>: From<E>,
{
Self::Serialize(Cow::from(msg))
}
/// Creates a [`Self::Deserialize`] error.
pub fn deserialize<E>(msg: E) -> Self
where
Cow<'static, str>: From<E>,
{
Self::Deserialize(Cow::from(msg))
}
/// Creates an [`Self::Http`] error.
pub fn http<E>(msg: E) -> Self
where
Cow<'static, str>: From<E>,
{
Self::Http(Cow::from(msg))
}
}