2020-11-29 18:50:51 +00:00
|
|
|
use thiserror::Error;
|
|
|
|
|
2021-04-17 23:59:59 +00:00
|
|
|
/// Errors thrown when the server loads its TOML config file
|
|
|
|
|
2020-11-29 21:38:23 +00:00
|
|
|
#[derive (Debug, Error)]
|
|
|
|
pub enum LoadTomlError {
|
2021-04-17 23:59:59 +00:00
|
|
|
/// The server's config file is readable by other users, meaning
|
|
|
|
/// that the file server module could accidentally serve it to
|
|
|
|
/// clients, and expose the server's API key.
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("Config file has bad permissions mode, it should be octal 0600")]
|
|
|
|
ConfigBadPermissions,
|
|
|
|
|
2021-04-17 23:59:59 +00:00
|
|
|
/// Wraps `std::io::Error`
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("I/O")]
|
|
|
|
Io (#[from] std::io::Error),
|
|
|
|
|
2021-04-17 23:59:59 +00:00
|
|
|
/// Wraps `std::string::FromUtf8Error`
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("UTF-8")]
|
|
|
|
Utf8 (#[from] std::string::FromUtf8Error),
|
|
|
|
|
2021-04-17 23:59:59 +00:00
|
|
|
/// Wraps `toml::de::Error`
|
2020-11-29 21:38:23 +00:00
|
|
|
#[error ("TOML")]
|
|
|
|
Toml (#[from] toml::de::Error),
|
|
|
|
}
|
|
|
|
|
2021-04-17 23:59:59 +00:00
|
|
|
/// Errors thrown when the server is starting up or serving requests
|
|
|
|
|
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),
|
|
|
|
|
2021-04-18 18:51:27 +00:00
|
|
|
#[error (transparent)]
|
2020-11-29 19:19:59 +00:00
|
|
|
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
|
|
|
}
|