viz_handlers/serve/
error.rs1use viz_core::{IntoResponse, Response, StatusCode, ThisError};
2
3#[derive(Debug, ThisError)]
5pub enum Error {
6 #[error("method not allowed")]
8 MethodNotAllowed,
9
10 #[error("invalid path")]
12 InvalidPath,
13
14 #[error("precondition failed")]
16 PreconditionFailed,
17
18 #[error("range could not be satisfied")]
20 RangeUnsatisfied(u64),
21
22 #[error("io: {0}")]
24 Io(#[from] std::io::Error),
25}
26
27impl IntoResponse for Error {
28 fn into_response(self) -> Response {
29 (
30 match self {
31 Self::MethodNotAllowed => StatusCode::METHOD_NOT_ALLOWED,
32 Self::InvalidPath => StatusCode::BAD_REQUEST,
33 Self::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
34 Self::RangeUnsatisfied(_) => StatusCode::RANGE_NOT_SATISFIABLE,
35 Self::Io(_) => StatusCode::INTERNAL_SERVER_ERROR,
36 },
37 self.to_string(),
38 )
39 .into_response()
40 }
41}
42
43impl From<Error> for viz_core::Error {
44 fn from(e: Error) -> Self {
45 e.into_error()
46 }
47}