1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-19 22:24:40 +01:00

50 lines
1.4 KiB
Rust
Raw Normal View History

use actix_web::{http::StatusCode, ResponseError};
use derive_more::Display;
/// Errors which can occur when serving static files.
#[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")]
IsNotDirectory,
2023-03-13 14:22:50 +00:00
/// Cannot render directory.
#[display(fmt = "unable to render directory without index file")]
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`.
fn status_code(&self) -> StatusCode {
StatusCode::NOT_FOUND
}
}
#[derive(Debug, PartialEq, Eq, Display)]
#[non_exhaustive]
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}')")]
BadStart(char),
2023-03-13 14:22:50 +00:00
/// Segment contained the wrapped invalid character.
#[display(fmt = "segment contained invalid character ('{_0}')")]
BadChar(char),
2023-03-13 14:22:50 +00:00
/// Segment ended with the wrapped invalid character.
#[display(fmt = "segment ended with invalid character: ('{_0}')")]
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,
}
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
}
}