ptth/crates/ptth_relay/src/errors.rs

79 lines
1.8 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 ("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 {
#[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)]
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
}