1use std::fmt;
2
3#[derive(Debug)]
13#[non_exhaustive]
14pub enum StaticError {
15 NotFound(String),
17 Traversal(String),
19 Io(std::io::Error),
21}
22
23impl fmt::Display for StaticError {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 StaticError::NotFound(path) => write!(f, "not found: {path}"),
27 StaticError::Traversal(path) => write!(f, "path traversal denied: {path}"),
28 StaticError::Io(e) => write!(f, "io error: {e}"),
29 }
30 }
31}
32
33impl std::error::Error for StaticError {
34 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35 match self {
36 StaticError::Io(e) => Some(e),
37 _ => None,
38 }
39 }
40}
41
42impl StaticError {
43 pub fn user_message(&self) -> String {
48 match self {
49 StaticError::NotFound(_) => "not found".to_string(),
50 StaticError::Traversal(_) => "not found".to_string(),
51 StaticError::Io(_) => "internal server error".to_string(),
52 }
53 }
54}
55
56impl From<std::io::Error> for StaticError {
57 fn from(e: std::io::Error) -> Self {
58 StaticError::Io(e)
59 }
60}