1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum ContainerError {
6 #[error("service not registered: {0}")]
8 NotRegistered(&'static str),
9
10 #[error("type mismatch when resolving: {0}")]
12 TypeMismatch(&'static str),
13
14 #[error("missing route parameter: {0}")]
16 MissingRouteParam(&'static str),
17
18 #[error("model not found")]
20 ModelNotFound,
21}
22
23#[cfg(feature = "axum")]
24impl axum::response::IntoResponse for ContainerError {
25 fn into_response(self) -> axum::response::Response {
26 use axum::http::StatusCode;
27
28 let status = match &self {
29 ContainerError::ModelNotFound => StatusCode::NOT_FOUND,
30 _ => StatusCode::INTERNAL_SERVER_ERROR,
31 };
32
33 axum::response::IntoResponse::into_response((status, self.to_string()))
34 }
35}