ptth/crates/ptth_relay/src/errors.rs

100 lines
2.2 KiB
Rust
Raw Normal View History

2020-11-29 16:58:56 +00:00
use thiserror::Error;
#[derive (Debug, Error)]
2020-11-29 16:58:56 +00:00
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 ("Bad server address")]
BadServerAddress,
2021-04-29 02:52:43 +00:00
#[error (transparent)]
TomlSerialization (#[from] toml::ser::Error),
2020-11-29 16:58:56 +00:00
#[error ("unknown config error")]
Unknown,
}
// I'm not sure how important this is, but it was already in the code
#[derive (Debug, Error)]
2020-11-29 16:58:56 +00:00
pub enum ShuttingDownError {
#[error ("Relay is shutting down")]
ShuttingDown,
}
#[derive (Debug, Error)]
2020-11-29 18:37:33 +00:00
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)]
2020-11-29 18:37:33 +00:00
pub enum RequestError {
2021-04-28 02:39:42 +00:00
#[error (transparent)]
2020-11-29 18:37:33 +00:00
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),
2021-04-28 02:39:42 +00:00
#[error ("Unknown server")]
UnknownServer,
#[error ("Bad request")]
BadRequest,
#[error ("Server never responded")]
ServerNeverResponded,
#[error ("Server timed out")]
ServerTimedOut,
#[error ("Relay shutting down")]
RelayShuttingDown,
2020-11-29 18:37:33 +00:00
#[error ("Error is mysterious!")]
Mysterious,
}
#[derive (Debug, Error)]
2020-11-29 16:58:56 +00:00
pub enum RelayError {
#[error ("Handlebars template file error")]
TemplateFile (#[from] handlebars::TemplateFileError),
2020-11-29 18:37:33 +00:00
#[error ("Hyper error")]
Hyper (#[from] hyper::Error),
2020-11-29 16:58:56 +00:00
}