1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-13 10:49:26 +00:00
actix-web/actix-files/src/error.rs

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-07 07:39:08 +00:00
pub enum FilesError {
2023-03-13 14:22:50 +00:00
/// Path is not a directory.
2020-02-07 14:16:32 +00: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-07 07:39:08 +00: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 10:07:39 +00:00
fn status_code(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}