2020-11-29 18:50:51 +00:00
|
|
|
use thiserror::Error;
|
|
|
|
|
2020-11-29 21:38:23 +00:00
|
|
|
#[derive (Debug, Error)]
|
|
|
|
pub enum LoadTomlError {
|
|
|
|
#[error ("Config file has bad permissions mode, it should be octal 0600")]
|
|
|
|
ConfigBadPermissions,
|
|
|
|
|
|
|
|
#[error ("I/O")]
|
|
|
|
Io (#[from] std::io::Error),
|
|
|
|
|
|
|
|
#[error ("UTF-8")]
|
|
|
|
Utf8 (#[from] std::string::FromUtf8Error),
|
|
|
|
|
|
|
|
#[error ("TOML")]
|
|
|
|
Toml (#[from] toml::de::Error),
|
|
|
|
}
|
|
|
|
|
2020-11-29 18:50:51 +00:00
|
|
|
#[derive (Debug, Error)]
|
|
|
|
pub enum ServerError {
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("Loading TOML")]
|
|
|
|
LoadToml (#[from] LoadTomlError),
|
|
|
|
|
|
|
|
#[error ("Loading Handlebars template file")]
|
|
|
|
LoadHandlebars (#[from] handlebars::TemplateFileError),
|
|
|
|
|
|
|
|
#[error ("API key is too weak, server can't use it")]
|
|
|
|
WeakApiKey,
|
|
|
|
|
2020-11-29 19:19:59 +00:00
|
|
|
#[error ("File server error")]
|
|
|
|
FileServer (#[from] super::file_server::errors::FileServerError),
|
2020-11-29 18:50:51 +00:00
|
|
|
|
2020-11-29 21:38:23 +00:00
|
|
|
// Hyper stuff
|
|
|
|
|
2020-11-29 19:19:59 +00:00
|
|
|
#[error ("Hyper HTTP error")]
|
2020-11-29 21:55:24 +00:00
|
|
|
Http (#[from] http::Error),
|
2020-11-29 19:19:59 +00:00
|
|
|
|
2020-11-29 21:55:24 +00:00
|
|
|
//#[error ("Hyper invalid header name")]
|
|
|
|
//InvalidHeaderName (#[from] hyper::header::InvalidHeaderName),
|
2020-11-29 19:19:59 +00:00
|
|
|
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("API key invalid")]
|
2020-11-29 21:55:24 +00:00
|
|
|
ApiKeyInvalid (http::header::InvalidHeaderValue),
|
2020-11-29 21:38:23 +00:00
|
|
|
|
|
|
|
// MessagePack stuff
|
|
|
|
|
|
|
|
#[error ("Can't parse wrapped requests in Step 3")]
|
2020-11-29 19:19:59 +00:00
|
|
|
CantParseWrappedRequests (rmp_serde::decode::Error),
|
2020-11-29 20:22:40 +00:00
|
|
|
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("Can't encode PTTH response as MsgPack in Step 5")]
|
|
|
|
MessagePackEncodeResponse (rmp_serde::encode::Error),
|
|
|
|
|
2020-11-29 20:22:40 +00:00
|
|
|
#[error ("Can't convert Hyper request to PTTH request")]
|
|
|
|
CantConvertHyperToPtth (#[from] ptth_core::http_serde::Error),
|
2020-11-29 21:38:23 +00:00
|
|
|
|
|
|
|
// Reqwest stuff
|
|
|
|
|
|
|
|
#[error ("Can't build HTTP client")]
|
|
|
|
CantBuildHttpClient (reqwest::Error),
|
|
|
|
|
|
|
|
#[error ("Can't collect non-200 error response body in Step 3")]
|
|
|
|
Step3CollectBody (reqwest::Error),
|
|
|
|
|
|
|
|
#[error ("Can't collect wrapped requests in Step 3")]
|
|
|
|
CantCollectWrappedRequests (reqwest::Error),
|
|
|
|
|
|
|
|
#[error ("Error in Step 5, sending response to client through relay")]
|
|
|
|
Step5Responding (reqwest::Error),
|
|
|
|
|
|
|
|
#[error ("Error in Step 7, getting response from relay after sending response to client")]
|
|
|
|
Step7AfterResponse (reqwest::Error),
|
|
|
|
|
|
|
|
// UTF-8
|
|
|
|
|
|
|
|
#[error ("Step 3 relay response (non-200 OK) was not valid UTF-8")]
|
|
|
|
Step3ErrorResponseNotUtf8 (std::string::FromUtf8Error),
|
2020-11-29 18:50:51 +00:00
|
|
|
}
|