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
use thiserror::Error;

#[derive (Debug, Error)]
pub enum ConfigError {
	#[error ("I/O error")]
	Io (#[from] std::io::Error),
	
	#[error ("UTF-8 decoding failed")]
	Utf8 (#[from] std::string::FromUtf8Error),
	
	#[error ("TOML parsing failed")]
	Toml (#[from] toml::de::Error),
	
	#[error ("base64 decoding failed")]
	Base64Decode (#[from] base64::DecodeError),
	
	#[error ("tripcode not 32 bytes after decoding")]
	TripcodeBadLength,
	
	#[error ("unknown config error")]
	Unknown,
}

// I'm not sure how important this is, but it was already in the code

#[derive (Debug, Error)]
pub enum ShuttingDownError {
	#[error ("Relay is shutting down")]
	ShuttingDown,
}

#[derive (Debug, Error)]
pub enum HandleHttpResponseError {
	#[error ("HTTP error")]
	Http (#[from] http::Error),
	
	#[error ("Missing PTTH magic header")]
	MissingPtthMagicHeader,
	
	#[error ("PTTH magic header is not base64")]
	PtthMagicHeaderNotBase64 (base64::DecodeError),
	
	#[error ("PTTH magic header could not be decoded as MessagePack")]
	PtthMagicHeaderNotMsgPack (rmp_serde::decode::Error),
	
	#[error ("Couldn't tell server something")]
	LostServer,
	
	#[error ("Relaying task panicked")]
	RelayingTaskPanicked (#[from] tokio::task::JoinError),
}

#[derive (Debug, Error)]
pub enum RequestError {
	#[error ("HTTP error")]
	Http (#[from] http::Error),
	
	#[error ("MessagePack encode error")]
	MsgPack (#[from] rmp_serde::encode::Error),
	
	#[error ("Handlebars rendering error")]
	Handlebars (#[from] handlebars::RenderError),
	
	#[error ("Error handling HTTP response")]
	HandleHttpResponse (#[from] HandleHttpResponseError),
	
	#[error ("Error is mysterious!")]
	Mysterious,
}

#[derive (Debug, Error)]
pub enum RelayError {
	#[error ("Handlebars template file error")]
	TemplateFile (#[from] handlebars::TemplateFileError),
	
	#[error ("Hyper error")]
	Hyper (#[from] hyper::Error),
}