aboutsummaryrefslogtreecommitdiffstats
path: root/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/errors.rs69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 80d9b9e..36bc29e 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -11,7 +11,23 @@ use thiserror::Error;
use crate::{renderer::render_error, MiniserveConfig};
#[derive(Debug, Error)]
-pub enum ContextualError {
+pub enum StartError {
+ /// Any kind of IO errors
+ #[error("{0}\ncaused by: {1}")]
+ IoError(String, std::io::Error),
+
+ /// In case miniserve was invoked without an interactive terminal and without an explicit path
+ #[error("Refusing to start as no explicit serve path was set and no interactive terminal was attached
+Please set an explicit serve path like: `miniserve /my/path`")]
+ NoExplicitPathAndNoTerminal,
+
+ /// In case miniserve was invoked with --no-symlinks but the serve path is a symlink
+ #[error("The -P|--no-symlinks option was provided but the serve path '{0}' is a symlink")]
+ NoSymlinksOptionWithSymlinkServePath(String),
+}
+
+#[derive(Debug, Error)]
+pub enum RuntimeError {
/// Any kind of IO errors
#[error("{0}\ncaused by: {1}")]
IoError(String, std::io::Error),
@@ -32,22 +48,6 @@ pub enum ContextualError {
#[error("Invalid path\ncaused by: {0}")]
InvalidPathError(String),
- /// Might occur if the HTTP credential string does not respect the expected format
- #[error("Invalid format for credentials string. Expected username:password, username:sha256:hash or username:sha512:hash")]
- InvalidAuthFormat,
-
- /// Might occur if the hash method is neither sha256 nor sha512
- #[error("{0} is not a valid hashing method. Expected sha256 or sha512")]
- InvalidHashMethod(String),
-
- /// Might occur if the HTTP auth hash password is not a valid hex code
- #[error("Invalid format for password hash. Expected hex code")]
- InvalidPasswordHash,
-
- /// Might occur if the HTTP auth password exceeds 255 characters
- #[error("HTTP password length exceeds 255 characters")]
- PasswordTooLongError,
-
/// Might occur if the user has insufficient permissions to create an entry in a given directory
#[error("Insufficient permissions to create file in {0}")]
InsufficientPermissionsError(String),
@@ -58,7 +58,7 @@ pub enum ContextualError {
/// Might occur when the creation of an archive fails
#[error("An error occurred while creating the {0}\ncaused by: {1}")]
- ArchiveCreationError(String, Box<ContextualError>),
+ ArchiveCreationError(String, Box<RuntimeError>),
/// More specific archive creation failure reason
#[error("{0}")]
@@ -75,28 +75,25 @@ pub enum ContextualError {
/// Might occur when trying to access a page that does not exist
#[error("Route {0} could not be found")]
RouteNotFoundError(String),
-
- /// In case miniserve was invoked without an interactive terminal and without an explicit path
- #[error("Refusing to start as no explicit serve path was set and no interactive terminal was attached
-Please set an explicit serve path like: `miniserve /my/path`")]
- NoExplicitPathAndNoTerminal,
-
- /// In case miniserve was invoked with --no-symlinks but the serve path is a symlink
- #[error("The -P|--no-symlinks option was provided but the serve path '{0}' is a symlink")]
- NoSymlinksOptionWithSymlinkServePath(String),
}
-impl ResponseError for ContextualError {
+impl ResponseError for RuntimeError {
fn status_code(&self) -> StatusCode {
+ use RuntimeError as E;
+ use StatusCode as S;
match self {
- Self::ArchiveCreationError(_, err) => err.status_code(),
- Self::RouteNotFoundError(_) => StatusCode::NOT_FOUND,
- Self::InsufficientPermissionsError(_) => StatusCode::FORBIDDEN,
- Self::InvalidHttpCredentials => StatusCode::UNAUTHORIZED,
- Self::InvalidHttpRequestError(_) => StatusCode::BAD_REQUEST,
- Self::DuplicateFileError => StatusCode::FORBIDDEN,
- Self::UploadForbiddenError => StatusCode::FORBIDDEN,
- _ => StatusCode::INTERNAL_SERVER_ERROR,
+ E::IoError(_, _) => S::INTERNAL_SERVER_ERROR,
+ E::MultipartError(_) => S::BAD_REQUEST,
+ E::DuplicateFileError => S::CONFLICT,
+ E::UploadForbiddenError => S::FORBIDDEN,
+ E::InvalidPathError(_) => S::BAD_REQUEST,
+ E::InsufficientPermissionsError(_) => S::FORBIDDEN,
+ E::ParseError(_, _) => S::BAD_REQUEST,
+ E::ArchiveCreationError(_, err) => err.status_code(),
+ E::ArchiveCreationDetailError(_) => S::INTERNAL_SERVER_ERROR,
+ E::InvalidHttpCredentials => S::UNAUTHORIZED,
+ E::InvalidHttpRequestError(_) => S::BAD_REQUEST,
+ E::RouteNotFoundError(_) => S::NOT_FOUND,
}
}