Skip to main content

actix_files/
error.rs

1use actix_web::{http::StatusCode, ResponseError};
2use derive_more::Display;
3
4/// Errors which can occur when serving static files.
5#[derive(Debug, PartialEq, Eq, Display)]
6pub enum FilesError {
7    /// Path is not a directory.
8    #[allow(dead_code)]
9    #[display("path is not a directory. Unable to serve static files")]
10    IsNotDirectory,
11
12    /// Cannot render directory.
13    #[display("unable to render directory without index file")]
14    IsDirectory,
15}
16
17impl ResponseError for FilesError {
18    /// Returns `404 Not Found`.
19    fn status_code(&self) -> StatusCode {
20        StatusCode::NOT_FOUND
21    }
22}
23
24/// Error which can occur with parsing/validating a request-uri path
25#[derive(Debug, PartialEq, Eq, Display)]
26#[non_exhaustive]
27pub enum UriSegmentError {
28    /// Segment started with the wrapped invalid character.
29    #[display("segment started with invalid character: ('{_0}')")]
30    BadStart(char),
31
32    /// Segment contained the wrapped invalid character.
33    #[display("segment contained invalid character ('{_0}')")]
34    BadChar(char),
35
36    /// Segment ended with the wrapped invalid character.
37    #[display("segment ended with invalid character: ('{_0}')")]
38    BadEnd(char),
39
40    /// Path is not a valid UTF-8 string after percent-decoding.
41    #[display("path is not a valid UTF-8 string after percent-decoding")]
42    NotValidUtf8,
43}
44
45impl ResponseError for UriSegmentError {
46    /// Returns `400 Bad Request`.
47    fn status_code(&self) -> StatusCode {
48        StatusCode::BAD_REQUEST
49    }
50}