1use serde::{Deserialize, Serialize};
2use snafu::Snafu;
3use strum_macros::EnumString;
4
5#[derive(Clone, Debug, Snafu, Deserialize, Serialize)]
6#[snafu(visibility(pub))]
7pub enum RequestError {
8 #[snafu(display("missing required parameter: {}", name))]
9 MissingParam { name: String },
10
11 #[snafu(display(
12 "incorrect parameter type: {} cannot be converted to {}",
13 actual,
14 expected
15 ))]
16 IncorrectParamType {
17 actual: RequestParamType,
18 expected: RequestParamType,
19 },
20
21 #[snafu(display("value {} is too large for type {}", value, expected))]
22 IntegerOverflow { value: u128, expected: String },
23
24 #[snafu(display("Unable to deserialize from JSON"))]
25 Json,
26
27 #[snafu(display("Unable to deserialize from binary"))]
28 Binary,
29
30 #[snafu(display("Unable to deserialise from tagged base 64: {}", reason))]
31 TaggedBase64 { reason: String },
32
33 #[snafu(display("Content type not specified or type not supported"))]
34 UnsupportedContentType,
35
36 #[snafu(display("HTTP protocol error: {}", reason))]
37 Http { reason: String },
38
39 #[snafu(display("error parsing {} parameter: {}", param_type, reason))]
40 InvalidParam { param_type: String, reason: String },
41
42 #[snafu(display("unexpected tag in TaggedBase64: {} (expected {})", actual, expected))]
43 TagMismatch { actual: String, expected: String },
44}
45
46#[derive(
47 Clone, Copy, Debug, EnumString, strum_macros::Display, Deserialize, Serialize, PartialEq, Eq,
48)]
49pub enum RequestParamType {
50 Boolean,
51 Hexadecimal,
52 Integer,
53 TaggedBase64,
54 Literal,
55}