2021-04-09 17:07:10 +00:00
|
|
|
use actix_web::{http::StatusCode, ResponseError};
|
2019-03-06 06:10:08 +00:00
|
|
|
use derive_more::Display;
|
|
|
|
|
|
|
|
/// Errors which can occur when serving static files.
|
|
|
|
#[derive(Display, Debug, PartialEq)]
|
2019-03-07 07:39:08 +00:00
|
|
|
pub enum FilesError {
|
2019-03-06 06:10:08 +00:00
|
|
|
/// Path is not a directory
|
2020-02-07 14:16:32 +00:00
|
|
|
#[allow(dead_code)]
|
2019-03-06 06:10:08 +00:00
|
|
|
#[display(fmt = "Path is not a directory. Unable to serve static files")]
|
|
|
|
IsNotDirectory,
|
|
|
|
|
|
|
|
/// Cannot render directory
|
|
|
|
#[display(fmt = "Unable to render directory without index file")]
|
|
|
|
IsDirectory,
|
|
|
|
}
|
|
|
|
|
2019-03-07 07:39:08 +00:00
|
|
|
/// Return `NotFound` for `FilesError`
|
|
|
|
impl ResponseError for FilesError {
|
2021-04-09 17:07:10 +00:00
|
|
|
fn status_code(&self) -> StatusCode {
|
|
|
|
StatusCode::NOT_FOUND
|
2019-03-06 06:10:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-13 17:49:58 +00:00
|
|
|
#[allow(clippy::enum_variant_names)]
|
2019-03-06 06:10:08 +00:00
|
|
|
#[derive(Display, Debug, PartialEq)]
|
2022-01-04 12:54:11 +00:00
|
|
|
#[non_exhaustive]
|
2019-03-06 06:10:08 +00:00
|
|
|
pub enum UriSegmentError {
|
|
|
|
/// The segment started with the wrapped invalid character.
|
|
|
|
#[display(fmt = "The segment started with the wrapped invalid character")]
|
|
|
|
BadStart(char),
|
2022-01-04 12:54:11 +00:00
|
|
|
|
2019-03-06 06:10:08 +00:00
|
|
|
/// The segment contained the wrapped invalid character.
|
|
|
|
#[display(fmt = "The segment contained the wrapped invalid character")]
|
|
|
|
BadChar(char),
|
2022-01-04 12:54:11 +00:00
|
|
|
|
2019-03-06 06:10:08 +00:00
|
|
|
/// The segment ended with the wrapped invalid character.
|
|
|
|
#[display(fmt = "The segment ended with the wrapped invalid character")]
|
|
|
|
BadEnd(char),
|
2022-01-04 12:54:11 +00:00
|
|
|
|
|
|
|
/// The path is not a valid UTF-8 string after doing percent decoding.
|
2022-01-04 12:58:40 +00:00
|
|
|
#[display(fmt = "The path is not a valid UTF-8 string after percent-decoding")]
|
2022-01-04 12:54:11 +00:00
|
|
|
NotValidUtf8,
|
2019-03-06 06:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return `BadRequest` for `UriSegmentError`
|
|
|
|
impl ResponseError for UriSegmentError {
|
2019-11-26 10:07:39 +00:00
|
|
|
fn status_code(&self) -> StatusCode {
|
|
|
|
StatusCode::BAD_REQUEST
|
2019-03-06 06:10:08 +00:00
|
|
|
}
|
|
|
|
}
|