1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Service not found: {0}")]
13 ServiceNotFound(String),
14
15 #[error("Service registration failed: {0}")]
17 RegistrationError(String),
18
19 #[error("Async service initialization failed: {0}")]
21 ContainerError(String),
22
23 #[error("HTTP server error: {0}")]
25 ServerError(String),
26
27 #[error("Route registration failed: {0}")]
29 RouteError(String),
30
31 #[error("Error: {0}")]
33 Other(String),
34}
35
36impl Error {
37 pub fn service_not_found(service_name: impl Into<String>) -> Self {
39 Self::ServiceNotFound(service_name.into())
40 }
41
42 pub fn registration_error(msg: impl Into<String>) -> Self {
44 Self::RegistrationError(msg.into())
45 }
46
47 pub fn container_error(msg: impl Into<String>) -> Self {
49 Self::ContainerError(msg.into())
50 }
51
52 pub fn server_error(msg: impl Into<String>) -> Self {
54 Self::ServerError(msg.into())
55 }
56
57 pub fn route_error(msg: impl Into<String>) -> Self {
59 Self::RouteError(msg.into())
60 }
61
62 pub fn other(msg: impl Into<String>) -> Self {
64 Self::Other(msg.into())
65 }
66}