2019-03-05 22:10:08 -08:00
|
|
|
use actix_web::{http::StatusCode, HttpResponse, ResponseError};
|
|
|
|
use derive_more::Display;
|
|
|
|
|
|
|
|
/// Errors which can occur when serving static files.
|
|
|
|
#[derive(Display, Debug, PartialEq)]
|
2019-03-06 23:39:08 -08:00
|
|
|
pub enum FilesError {
|
2019-03-05 22:10:08 -08:00
|
|
|
/// Path is not a directory
|
2020-02-07 23:16:32 +09:00
|
|
|
#[allow(dead_code)]
|
2019-03-05 22:10:08 -08: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-06 23:39:08 -08:00
|
|
|
/// Return `NotFound` for `FilesError`
|
|
|
|
impl ResponseError for FilesError {
|
2019-03-05 22:10:08 -08:00
|
|
|
fn error_response(&self) -> HttpResponse {
|
|
|
|
HttpResponse::new(StatusCode::NOT_FOUND)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Display, Debug, PartialEq)]
|
|
|
|
pub enum UriSegmentError {
|
|
|
|
/// The segment started with the wrapped invalid character.
|
|
|
|
#[display(fmt = "The segment started with the wrapped invalid character")]
|
|
|
|
BadStart(char),
|
|
|
|
/// The segment contained the wrapped invalid character.
|
|
|
|
#[display(fmt = "The segment contained the wrapped invalid character")]
|
|
|
|
BadChar(char),
|
|
|
|
/// The segment ended with the wrapped invalid character.
|
|
|
|
#[display(fmt = "The segment ended with the wrapped invalid character")]
|
|
|
|
BadEnd(char),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return `BadRequest` for `UriSegmentError`
|
|
|
|
impl ResponseError for UriSegmentError {
|
2019-11-26 16:07:39 +06:00
|
|
|
fn status_code(&self) -> StatusCode {
|
|
|
|
StatusCode::BAD_REQUEST
|
2019-03-05 22:10:08 -08:00
|
|
|
}
|
|
|
|
}
|