1use sova_core::extend::ErrorResponse;
2use sova_core::{Error, IntoResponse, Response};
3
4#[derive(Debug, thiserror::Error)]
5pub enum FsError {
6 #[error("not found")]
7 NotFound,
8 #[error("forbidden path")]
9 Forbidden,
10 #[error("{0}")]
11 Msg(String),
12 #[error(transparent)]
13 Io(#[from] std::io::Error),
14}
15
16impl From<FsError> for Error {
17 fn from(err: FsError) -> Self {
18 match err {
19 FsError::NotFound => Error::NotFound,
20 FsError::Forbidden => Error::Forbidden,
21 FsError::Msg(m) => Error::Internal(m),
22 FsError::Io(e) if e.kind() == std::io::ErrorKind::NotFound => Error::NotFound,
23 FsError::Io(e) if e.kind() == std::io::ErrorKind::PermissionDenied => Error::Forbidden,
24 FsError::Io(e) => Error::Internal(e.to_string()),
25 }
26 }
27}
28
29impl IntoResponse for FsError {
30 fn into_response(self) -> Response {
31 Error::from(self).into_response()
32 }
33}
34
35impl ErrorResponse for FsError {}