threema_gateway/
errors.rs1use std::io::Error as IoError;
4
5use reqwest::Error as ReqwestError;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
10pub enum ApiError {
11 #[error("bad sender or recipient")]
13 BadSenderOrRecipient,
14
15 #[error("bad credentials")]
17 BadCredentials,
18
19 #[error("no credits")]
21 NoCredits,
22
23 #[error("target ID not found")]
25 IdNotFound,
26
27 #[error("message is too long")]
29 MessageTooLong,
30
31 #[error("internal server error")]
33 ServerError,
34
35 #[error("bad hash length")]
37 BadHashLength,
38
39 #[error("bad blob")]
41 BadBlob,
42
43 #[error("bad blob ID")]
45 BadBlobId,
46
47 #[error("invalid MAC")]
49 InvalidMac,
50
51 #[error("rate limit reached")]
53 RateLimitReached,
54
55 #[error("request error: {0}")]
57 RequestError(#[source] ReqwestError),
58
59 #[error("request URL parse error: {0}")]
61 RequestUrlParseError(#[from] url::ParseError),
62
63 #[error("I/O error: {0}")]
65 IoError(#[from] IoError),
66
67 #[error("parse error: {0}")]
69 ParseError(String),
70
71 #[error("other: {0}")]
73 Other(String),
74}
75
76impl From<ReqwestError> for ApiError {
77 fn from(err: ReqwestError) -> Self {
78 Self::RequestError(err.without_url())
80 }
81}
82
83#[derive(Debug, Error)]
85pub enum ApiOrCacheError<C: core::error::Error> {
86 #[error("api error: {0}")]
88 ApiError(ApiError),
89 #[error("cache error: {0}")]
91 CacheError(C),
92}
93
94#[derive(Debug, PartialEq, Clone, Error)]
96pub enum CryptoError {
97 #[error("bad key: {0}")]
99 BadKey(String),
100
101 #[error("bad nonce")]
103 BadNonce,
104
105 #[error("invalid padding")]
107 BadPadding,
108
109 #[error("decryption failed")]
111 DecryptionFailed,
112
113 #[error("encryption failed")]
115 EncryptionFailed,
116}
117
118#[derive(Debug, PartialEq, Clone, Error)]
120pub enum ApiBuilderError {
121 #[error("missing private key")]
123 MissingKey,
124
125 #[error("invalid libsodium private key: {0}")]
127 InvalidKey(String),
128}
129
130#[derive(Debug, PartialEq, Clone, Error)]
132pub enum FileMessageBuilderError {
133 #[error("illegal combination: {0}")]
135 IllegalCombination(&'static str),
136}