2021-04-09 18:07:10 +01:00
|
|
|
use actix_web::{http::StatusCode, ResponseError};
|
2019-03-05 22:10:08 -08:00
|
|
|
use derive_more::Display;
|
|
|
|
|
|
|
|
/// Errors which can occur when serving static files.
|
2022-07-23 17:26:48 +02:00
|
|
|
#[derive(Debug, PartialEq, Eq, Display)]
|
2019-03-06 23:39:08 -08:00
|
|
|
pub enum FilesError {
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Path is not a directory.
|
2020-02-07 23:16:32 +09:00
|
|
|
#[allow(dead_code)]
|
2023-03-13 14:22:50 +00:00
|
|
|
#[display(fmt = "path is not a directory. Unable to serve static files")]
|
2019-03-05 22:10:08 -08:00
|
|
|
IsNotDirectory,
|
|
|
|
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Cannot render directory.
|
|
|
|
#[display(fmt = "unable to render directory without index file")]
|
2019-03-05 22:10:08 -08:00
|
|
|
IsDirectory,
|
|
|
|
}
|
|
|
|
|
2019-03-06 23:39:08 -08:00
|
|
|
impl ResponseError for FilesError {
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Returns `404 Not Found`.
|
2021-04-09 18:07:10 +01:00
|
|
|
fn status_code(&self) -> StatusCode {
|
|
|
|
StatusCode::NOT_FOUND
|
2019-03-05 22:10:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-23 17:26:48 +02:00
|
|
|
#[derive(Debug, PartialEq, Eq, Display)]
|
2022-01-04 15:54:11 +03:00
|
|
|
#[non_exhaustive]
|
2019-03-05 22:10:08 -08:00
|
|
|
pub enum UriSegmentError {
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Segment started with the wrapped invalid character.
|
|
|
|
#[display(fmt = "segment started with invalid character: ('{_0}')")]
|
2019-03-05 22:10:08 -08:00
|
|
|
BadStart(char),
|
2022-01-04 15:54:11 +03:00
|
|
|
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Segment contained the wrapped invalid character.
|
|
|
|
#[display(fmt = "segment contained invalid character ('{_0}')")]
|
2019-03-05 22:10:08 -08:00
|
|
|
BadChar(char),
|
2022-01-04 15:54:11 +03:00
|
|
|
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Segment ended with the wrapped invalid character.
|
|
|
|
#[display(fmt = "segment ended with invalid character: ('{_0}')")]
|
2019-03-05 22:10:08 -08:00
|
|
|
BadEnd(char),
|
2023-03-13 14:30:21 +00:00
|
|
|
|
|
|
|
/// Path is not a valid UTF-8 string after percent-decoding.
|
|
|
|
#[display(fmt = "path is not a valid UTF-8 string after percent-decoding")]
|
|
|
|
NotValidUtf8,
|
2019-03-05 22:10:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ResponseError for UriSegmentError {
|
2023-03-13 14:22:50 +00:00
|
|
|
/// Returns `400 Bad Request`.
|
2019-11-26 16:07:39 +06:00
|
|
|
fn status_code(&self) -> StatusCode {
|
|
|
|
StatusCode::BAD_REQUEST
|
2019-03-05 22:10:08 -08:00
|
|
|
}
|
|
|
|
}
|